Steve Kim
Steve Kim

Reputation: 5591

Automatic "Submit" after onload

So, here is the form that I have:

<form class="cart" method="post" >
    <button type="submit" id="add_to_cart_auto_button" class="add_my_post"><?php echo $item->single_add_to_cart_text(); ?></button>
</form>

Here is jQuery to trigger automatic click once the page is loaded:

<script>// <![CDATA[
    jQuery(window).load(function() {   
        jQuery("#add_to_cart_auto_button").trigger('submit');    
        return false;
    });   
// ]]></script> 

But the code itself is not doing anything (no error, no action).
So, once the page is loaded, I want this button to be automatically clicked to trigger next steps.

What am I doing wrong?

Upvotes: 0

Views: 58

Answers (1)

Samir Das
Samir Das

Reputation: 1908

submit event is applicable for form NOT for the input. You are trying to trigger submit event for the input. Please use following instead:

$( "form.cart" ).trigger( "submit" );

Upvotes: 1

Related Questions