Practical eCommerce

Authorize.Net

Manage Subscriptions · Subscribe Now · F.A.Q.'s

HOME · Tuesday, May 13, 2008

Development & Programming

Video Tutorial: Validating A Form With JavaScript

Useful for client-side validation

By: Brian Getting
Comments: 7

In form validation two common questions often arise. The first is how do you ensure once you've asked for an email address on an online form, you actually get one? The second is how do you make sure your customers include a name and phone number when they contact you from your website? The answer lies in form validation, or checking a form's data before it is submitted, and JavaScript is particularly useful for client-side validation.

In this tutorial, we will create an online contact form our visitors could use to send us an email message. To guarantee they include their name, email address and a short message when they submit the form, we will use a simple JavaScript function to illustrate how validation works. By checking our form data before we submit the form, we will eliminate the potential of receiving a blank email from JavaScript enabled users.

Software Used: TextMate
Additional Files: form_validation.zip

Click the image below to launch the tutorial.

Validating a Form with JavaScript

This video tutorial requires Flash Player version 8 or above. Please forward us your ideas for additional video tutorials, via our Contact Us form.

Advertisement

Blinklist | Del.icio.us | Furl | Ma.gnolia | Newsvine | Spurl | Reddit | Technorati

Published on Thursday, September 20, 2007

Comments:

Hey, I thought it was an informative tutorial and quite important, too, for web developers to include form validation. However, as you mentioned, with client side validation if the client does not have JavaScript then it would not work. In that case won't server side be a better choice? Maybe you could have a tutorial with that as well.

Posted by: Andre Brathwaite
Thursday, September 20, 2007

Great tutorial! Thank you.

How can we set up a validation so that the user has to confirm their email address by clicking on a link sent to the address they entered?

I find that some customers put in fake email addresses just to get through to the next section of our website.

I would like to have them validate their email address by email confirmation.

Any advice?

Posted by: Paul E.
Friday, September 21, 2007

Andre -
Thanks for the suggestion. In an ideal application, there would be both JavaScript validation on the client side (to catch bad entries right away and save a request to the server) and also some sort of server-side validation as well to ensure that the data being put into a database is correct. In order to do a server-side tutorial, it would have to be in a specific scripting language such as PHP, Rails, ASP, etc... I'm interested to hear what people think would be the most useful.

Paul-
To pull off what you are looking to do, you will need to have a system where the user would create an account (for example) by entering their email address. The server would then send that email address an email with a link to verify their address. Once they click that link, another script on the server would verify the account and continue the process. Again, this is all done with a server-side scripting language such as PHP, Ruby, ASP...

Posted by: Brian Getting
Sunday, September 23, 2007

Having a problem getting my PHP form to submit. The script correctly validates the form fields to be sure each is filled in, but when I click on "Submit Form" nothing happens. The data is not sent to the SQL database.

Any help or guidance you can give would be greatly appreciated.

The Form:


EBS PowerPad










Mass Scanner Request Form



Please complete the form below to request mass scanners for your station. All form fields must be completed in order to process your request.




 




Name:




Employee
Number:




Email:




Station ID::




Quantity of Scanners




Request Justification:




Submit Form




 


The scripts.js file:

function validate() {
var name = document.getElementById('name');
var empNum = document.getElementById('empNum');
var email = document.getElementById('email');
var stationID = document.getElementById('stationID');
var request = document.getElementById('request');
var comment = document.getElementById('comment');
var error = '';

if (name.value == '') {
error += "Please enter your name.\n";
}
if (empNum.value == '') {
error += "Please enter your employee number.\n";
}
if (email.value == '') {
error += "Please enter an email address.\n";
}
if (stationID.value == '') {
error += "Please enter a station ID.";
}
if (request.value == '') {
error += "Please enter the quantity of scanners.\n";
}
if (comment.value == '') {
error += "Please enter a quantity justification.\n";
}

if (error != '') {
alert(error);
return false;
} else {
return true;
}

}

Posted by: David Moore
Friday, October 05, 2007

Great tutorial! Thank you. http://createunity.biz - business. all about business

Posted by: toxa
Thursday, April 17, 2008

This script seems to work fine when used with an action address being sent to the server, however when I try to implement it using a "mailto: xxx" as my action then the form is submitted without any validation being made. Please give me examples or samples of how to use this correctly with Mailto Forms.

Posted by: Ralph Cassidy
Monday, April 21, 2008

Thanks Brian I am a beginner and I find your article quite useful, as I am working on validation at the moment.

Posted by: paulette miller
Monday, May 12, 2008

↑ Back to Top

Leave a comment:

Please enter the following security code exactly as it appears.


Comments are stripped of HTML code upon submission. All comments are submitted for approval prior to being published. Please allow up to 24 hours for the approval process to take place. Practical eCommerce reserves the right to remove any comment at any time for any reason.

 


Related Articles

Articles at Practical eCommerce related to Video Tutorial: Validating A Form With JavaScript:

Related Podcasts

Podcasts at Practical eCommerce related to Video Tutorial: Validating A Form With JavaScript:

Related Links

External links related to this article.

RSS 2.0 Feeds

Atom 1.0 Feeds

Technorati Tags

Ecommerce Articles

Browse All Articles
Browse our complete archive of ecommerce articles.
Accounting, Management & Legal
Ecommerce articles related to managing a small business including ecommerce accounting, business strategy and legal considerations.
Conversion & Usability
Online business articles about converting web site visitors into customers and how to gauge and improve your business website's usability.
Development & Programming
Articles to help designers, developers and programmers create successful, search engine friendly ecommerce websites and improve existing ones.
Hosting, Infrastructure & Software
Articles for ecommerce businesses about ecommerce web hosting, business infrastructure, business strategy and helpful ecommerce & small business software.
Interviews & Profiles
Interviews with prominent ecommerce business personalities and profiles of successful online businesses.
Inventory & Shipping
Ecommerce articles about inventory management, ecommerce order fulfillment and product shipping considerations.
Marketing & Revenue Growth
Articles relating to online marketing, email marketing and using the Internet to growing your business.
Search Engine Optimization
Search engine optimization articles for ecommerce business owners, strategists, marketers and developers.
Shopping Carts & Online Payments
Articles covering ecommerce shopping cart platforms and options for choosing an online payment gateway.
Training & Education
Tutorials and articles providing training and education for ecommerce business owners and developers of ecommerce websites.

Search Articles

Ecommerce Community

Ecommerce Blogs
Read our blogs about ecommerce topics written by industry professionals.
Community Forum
Connect with other ecommerce professionals to trade advice and answers in our community forum.
Podcasts
Check out our ecommerce podcasts covering topics ranging from interviews to tutorials.
RSS Content Feeds
Subscribe to our RSS feeds and have fresh ecommerce content delivered to you.

Ecommerce Resources

Free Email Newsletter
Sign up for Ecommerce Notes, our free email newsletter for ecommerce business owners and developers.
Ecommerce Directory
Browse our directory of ecommerce products and services, or submit your own listing in our directory.
Ecommerce Glossary
Familiarize yourself with terminology or submit terms to help others with our Ecommerce Glossary.
Events Calendar
Find out about upcoming ecommerce events or invite other ecommerce professionals by posting your own event.
Press Releases
Browse ecommerce related press releases and post your own press release for distribution.
Ecommerce Store & Back Issues
Pick up back issues of Practical eCommerce magazine along with other merchandise from Practical Ecommerce

About Practical eCommerce

Frequently Asked Questions
Look at frequently asked questions regarded using our website, subscribing to our magazine and more.
Advertising Information
Information about advertising in Practical eCommerce magazine, on our website, or in our email newsletters.
Editorial Sharing
Learn about options for sharing our content with your visitors, customers or employees.
About Us
Learn more about Practical Ecommerce magazine and meet our staff.
Contact Us
Contact Practical Ecommerce at any time for more information. We'd love to hear from you.
AdvertisementEndiciaClearCartArial Software

Copyright 2007 Confluence Distribution, Inc. and Practical eCommerce.
All Rights Reserved.

Privacy PolicyConditions of UseContact Us