Halhelms
SIGN UP FOR MY NEWSLETTER

www.savorgold.com is top on wow gold and runescape gold and World of Warcraft gold provider list for trusted services. Their reputation seems to growing by the minute, which isn't surprising because they are one of the safest sellers of Gold. Delivery speed and customer service are very good. They aslo are giving some bonus items depending on the amount of gold you purchase.

 
 
Halhelms

Recent Comments

Recent Entries

RSS

Learning jQuery, Day 8 : Preventing Form Double-Processing

Today is a quick tutorial on how to prevent the problem of a user clicking the "submit" button more than once -- usually in the case of a slow-responding form processing page.

Here is the form:

<form id="form_processor" action="doForm.cfm" method="post">
   <label for="username">User name: </label><input type="text" id="username" name="username" /><br />
   <label for="password">Password: </label><input type="password" id="password" name="password" /><br />
   <span id="submit"><input type="submit" value="OK" /></span>
</form>

<cfinclude template="form.pgm">

I've included "form.pgm", where my JavaScript looks like this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
   $('#form_processor').submit(function(){
      $('#submit').html('<img src="25.gif" border="0"> Processing');
   });
</script>

When the user clicks the submit button, the form processing will be intercepted by this code. I then use jQuery to replace the form button with a spinning button and the word "Processing".

You can see it running http://dev.citymind.com:8500/test/blog_jquery/day8/form.cfm

For the form processing page, I simulated a slow page with this code:

<cfset thread = CreateObject('java', 'java.lang.Thread')>
<cfset thread.sleep(4000)>
<cfoutput>
   <p>Your form has been processed.</p>
   <p>Your username is #form.username# and your password is #form.password#</p>
</cfoutput>

Zipped files

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Will B.'s Gravatar Hal, you could also (and not a bad idea to) disable the submit button with:
$('#submit').attr('disabled', 'disabled');

Even with the text change, they could still click it. Or better yet, you could use the .blockUI() plugin to gray out the form (or the div containing the form) afterwards.
# Posted By Will B. | 4/25/09 11:22 PM
Will B.'s Gravatar My mistake, I just noticed you actually changed the entire HTML.
# Posted By Will B. | 4/25/09 11:23 PM
Adrian Lynch's Gravatar Nothing to do with the point of this post, but it might be an idea to preload the image so you don't get the broken image as soon as you click submit.
# Posted By Adrian Lynch | 5/3/09 11:52 AM
Tom Sucaet's Gravatar With coldfusion (cfinput) you can do the exact same thing with the validate attribute:

<cfinput type="submit" value="ok" name="ok" validate="SubmitOnce" />
# Posted By Tom Sucaet | 5/28/09 4:29 AM
 
   
Clicky Web Analytics