Better Form Usability with jQuery
Web 2.0 is really taking off, and that means websites are utilizing information in databases a lot more. This also means we are using web forms for many more reasons as well. Whether it just be a simple register form, e-commerce purchase form, contact form, or even a profile edit form. Let’s face it, forms are everywhere now! Since web developers are forced to use forms, why not use JavaScript, mainly the jQuery library to enhance the end-users experience with forms?
Labeling
First and foremost, our forms need labels so the user knows what information to enter into the field. We don’t want them putting their name where their email is supposed to go. That will either throw an error during the validation of the form, or it won’t get stored in the database correctly. Keep your HTML labels simple, if you want to say more, why not use jQuery and populate the input item itself with some text? Or we can even show the user more information when they are focused on one input element, or hovered.
Layout
After you get your information organized for your form, you need to figure out the best way to present the information. Are the labels going to go on top, left, bottom, or the right side of the input box? All can be appropriate if executed the right way. Think about the information your asking then make a few quick sketches for displaying the information. If you want to even take it a step further, go ahead and visit designers toolbox and download their form design package which allows you to design forms easier in Photoshop!
Was It a Success?
One thing people forget about all the time is notifying the user if the information was received and filled out correctly. Its easy to inform a user if the information was wrong because half of the time, the form won’t submit. But what about the other half that fill it out right and want to move on to the next step? Lets say your a salesman and you need a customer to fill out paperwork on a wireless phone they are buying. Are you the salesman than runs them through as fast as you can? Or are you the salesman that says thank you after getting information and helping them understand each step? Same with form information… If its a simple contact form, redirect them to a thank you page and let them know when they can expect a response. If its a multi-page form make it clear where they are in the process; and don’t forget to thank them after its all complete.
How can jQuery Help?
Now were getting to the good stuff! Now that we have our form all planned out and ready for deployment, lets use jQuery help the user fill out a form, send information without reloading pages, and let the user know if there are problems, or if the can pass go and collect two-hundred dollars.
Hover Labels
Name
Enter your first name, or your first and last name here. Or even your favorite nickname!
Name
Email
Please enter a valid email address here. Fake or mistyped emails won't send!
Email
Message
Leave me some feedback, ask me a question, or just leave me a quick comment; I'll get back with you asap!
Message
// On mouse over show some help
$'input, textarea'mouseoverfunction
$thisprevprevfadeIn'slow';
// On mouse out show some help
$'input, textarea'mouseoutfunction
$thisprevprevfadeOut'slow';
AJAX Sumbit
$'form'submitfunction
// Grab data
var contactname = $'#name'attr'value';
var contactemail = $'#email'attr'value';
var contactmessage = $'#message'attr'value';
// Send it
jQuerypost'index.php' name : contactnameemail : contactemailmessage : contactmessage functiondata
ifdata == 'true'
$'.status'html'<span class="success">Thank you ' + contactname + ', for contacting me!</span>';
$'#message'attr'value''What do you want to tell me?';
$'.status'fadeIn'slow';
$'.status'animate opacity: 1.0 5000;
$'.status'fadeOut'slow';
else
$'.status'html'<span class="error">Sorry ' + contactname + ', it seems that the contact form didn\'t work.</span>';
$'.status'fadeIn'slow';
$'.status'animate opacity: 1.0 5000;
$'.status'fadeOut'slow';
// Keep the form from refreshing the page
return false;
Back-End Validation (more reliable)
AJAX Confirmation
ifdata == 'true'
$'.status'html'<span class="success">Thank you ' + contactname + ', for contacting me!</span>';
$'#message'attr'value''What do you want to tell me?';
$'.status'fadeIn'slow';
$'.status'animate opacity: 1.0 5000;
$'.status'fadeOut'slow';
else
$'.status'html'<span class="error">Sorry ' + contactname + ', it seems that the contact form didn\'t work.</span>';
$'.status'fadeIn'slow';
$'.status'animate opacity: 1.0 5000;
$'.status'fadeOut'slow';
If your still a little confused on how to put this together yourself, feel free to check out the live demo and grab the source code if you want! Its not a whole lot, but I sure hope it helps with something!