Results 1 to 2 of 2

Thread: Updating cart instead of Form submit

  1. #1
    Join Date
    Aug 2012

    Updating cart instead of Form submit

    This allows to update my cart, but returns back to the top of the page.

    I don;t want it to return back on top, so how can i do it using Javascript ?

    Below is my code for the form.

    <form class="product_form" enctype="multipart/form-data" action="#" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_<?php echo wpsc_the_product_id(); ?>">
    <input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
    <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
    <input type="hidden" name="wpsc_quantity_update" value="500">
    <input type="submit" name="500" class="image-button500 wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" value=''/>

  2. #2
    Join Date
    Feb 2003
    Michigan, USA
    If using jQuery:

    jQuery.delegate("form[name=product_form]", "submit", function(event) {
    	// code to update your shopping cart
    The key is the method calls to event.preventDefault() and event.stopPropagation(). This prevents the form from submitting (and therefore changing the URL of the page to include the "#") and keeps the submit event from bubbling up from the <form> tag to the top of the document tree.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles