DuH
DuH

Reputation: 15

Count the number of times a submit button has been clicked

Is there a way I can tell how many times a form submit button has been clicked using jQuery? If so, can someone please provide a code sample? Thanks!

Upvotes: 1

Views: 10917

Answers (3)

Hugh
Hugh

Reputation: 1212

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++;
        });
});

Upvotes: 4

SLaks
SLaks

Reputation: 887937

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

Upvotes: 0

Daniel Vassallo
Daniel Vassallo

Reputation: 344471

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.

Upvotes: 1

Related Questions