Question

Shopping cart form contains validation form with ajax submit. If validation fails, alert() box appears and submit is cancelled by return false If validation fails, submit method is not called anymore. Subsequent clicks to button are ignored.

Only first click in green Lisa ostukorvi button causes alert box. Subsequent clicks are ignored, submit() event does not fire. This occurs in IE10, FireFox & Chrome. How to fix this?

<script>
var request;
$(function() {
$(".browse-addtocart-form").submit(function(event){
    if (request) {
        request.abort();
    }
    var $form = $(this);
    var $inputs = $form.find("input, select, button, textarea");
    var serializedData = $form.serialize();
    var q = parseInt(this.quantity.value, 10);
    if(isNaN(q) || q === 0){
      alert('Fill quantity');
      $(this.quantity).focus();
      // TODO: Why this causes submit event not to occur on subsequent clicks:
      return false;
      }

    request = $.post('/AddToCart', serializedData );
    return false;
    });
   });
</script>


 <form class='browse-addtocart-form' action="/AddToCartPost" method="post">
<input type="submit" value="Add to cart" class='button green small bigrounded' />
</form>
</html>

jquery, jquery-ui, ASP .NET MVC2 are used.

Was it helpful?

Solution

hi you should use click function like this $("#submitId").click(function () { /* your code*//}); and give your submit botton an id

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top