0

I want to prevent a form to submit twice after changing a select box. I tried to use e.preventDefault(), but it makes no difference.

 $(document).ready(function() { $(document).on("change","#select1", function(e){ e.preventDefault(); $("#form1").submit(); }); }); 

3 Answers 3

1

The form won't submit twice with that code, but it does'nt prevent the form from submitting either, it just prevents the change event on the select, as that is the element and event you are binding to.

Sign up to request clarification or add additional context in comments.

1 Comment

But what could it be than that is submitting the form twice? Hitting the submit button doesn't fire submit twice.
0

You need to preventDefault on the form's submit event:

$('form').live('submit', function (e) { e.preventDefault(); }); 

Comments

0

Something like that?

$(document).ready(function() { var changed = 0; $(document).on("change","#select1", function(e) { changed++; if( changed > 1) return false; $("#form1").submit(); }); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.