The Wayback Machine - https://web.archive.org/web/20110616015620/http://www.webreference.com:80/programming/javascript/jsforms/

WebReference.com logo
tip archive  •   about  •   sitemap  •   contact  •   jobs  •   write for us  •   subscribe

Newletters


[next]

Bring Your Forms to Life With Javascript

By Kris Hadlock

Digg This Add to del.icio.us

C/C++ Developer (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

In this article we'll take a look at how to prevent errors in your forms and ultimately bring them to life through JavaScript. The source code for the samples used in this article can be downloaded here and a live example can be viewed here. Now let's add some life to those old forms.

Creating a Basic Web Form

We'll start by creating a basic registration form with a few common form elements. We'll create an HTML page and add the the registration form code from listing 1, shown below.

The code from listing 1 will allow us to post data to a server and register a user. It could also display any errors or warnings based on server-side results, but this is equivalent to asking your users to complete a form and hope that it will be sent successfully. There's really no reason to make a user wait when we can provide them immediate feedback and prevent issues from occurring rather than having to deal with them after the fact. Having said that, it would be useful to have a JavaScript object that allows us to validate all our forms without having to rewrite code everytime we create a new form. Let's take a look at how to accomplish this by creating a reusable JavaScript validation object and tying it to the form we just created.


[next]

Recent Articles

WebReference.com site name
The Dangers of HTML5: WebSockets and Stable Standards
Internet Explorer 6: What Have We Learned?
Crank Up the Volume with HTML5 Music
internet.com site name
Switchvox announces version 5.0 of its IP PBX
Cisco Adds Cloud-Based Wireless Controller to Wi-Fi Portfolio
PC Buyer's Guide for Gaming Enthusiasts


Internet.com
The Network for Technology Professionals

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers