Web form usability: Better form submission feedback with jQuery
Reading time: About 1 minute
Browsers fail to give users effective feedback when the user submits a form. Users respond by clicking the submit button over and over. The problem compounds when users find out they’ve been charged 5 times or when you receive 5 contact submissions. Bummer.
The solution is to replace the submit button with a friendly message letting the user know the form is working. See below…
Sweet! How did we do that? jQuery makes it super simple.
1 2 3 4 5 $(function () { // make this code initialize when DOM loads $('form').submit(function () { // optional: replace "form" with whatever CSS selector you want (ex: ID or class) $('input[type="submit"]', this).replaceWith('<p><strong>Sending...</strong></p>'); // optional: change "Sending..." to something else }); });If you don’t use jQuery already, grab a copy of jQuery and shame yourself for not using it sooner.
Author’s note: People have been commenting that this could be just as easy without jQuery. While this is true, I figured it was better to show how to do it with jQuery because many people are interested in jQuery, and this code snippet gives them an extra idea how jQuery works.
16 comments skip to comment form
Nikhil Sheth said— 2 hours later
John Sheehan said— 2 hours later
Brian Cray said— 10 hours later
Stephen said— 10 hours later
Brian Cray said— 10 hours later
Stephen said— 11 hours later
Sean O said— 11 hours later
Brian Cray said— 11 hours later
Cezary Tomczyk said— 1 month later
Rob said— 1 month later
Tim said— 1 month later
LadyHoo said— 2 months later
Bill Reed said— 4 months later
Patricia Quintanilla said— 10 months later
Silver said— on July 28, 2009 later
tom said— on July 28, 2009 later
Respond to this post—