tags:

views:

37

answers:

3

Is there a way I can tell how many times a from submit button has been clicked using JQuery if so can some one please provide a code sample? Thanks!

+1  A: 

If you are posting the form to the server, you may find it easier, and more reliable, to track the form submissions from the server-side.

Daniel Vassallo
+1  A: 

Easy.

html:

<form id="form">
    <input type="button" id="Submit" name="Submit" value="Submit" />
</form>

javascript:

var count = 0;
$(document).ready(function(){
    $("form#Submit").submit(function(){
             count++;
        });
});
Hugh
You missed a space in your selector.
SLaks
It's not required for "elementType:identifier" combinations (i.e. `("form#Submit")` or `("form.submit")`).
Nathan Taylor
@Nathan: `#Submit` is an element in the form. His code will not match anything.
SLaks
Good point. I was thinking in terms of a form named submit, but yeah based on the html, that definitely won't work! :)
Nathan Taylor
A: 

You can increment a variable in the click or submit events.

SLaks