Free Scripts


Form Input Validation JavaScript: Step 1b
by Christopher Heng

You will need to replace the "email" in both the "name" attribute of the INPUT tag as well as the function checkform to the actual name of the field you want to check. For example, if you want to check a field called "fullname", replace all instances of "email" in the function with "fullname".
 
The function begins by checking that the field named "email" is not an empty string. If it is, it will call the alert() function to display a dialog box with the message "Please enter your email address." It then calls form.email.focus() to place the text cursor in the email field for the convenience of the visitor and returns "false" to prevent the form from being submitted. On the other hand, if the field was not empty, nothing is executed and the form is submitted as usual.
 
What if you want to check more than one field? Simply copy everything from the
    // ** START **
line to the
    // ** END **
line and place it immediately below the existing
    // ** END **
line, before the final closing brace "}". Then change all occurences of "email" in the new block to the name of the field you wish to check. You can duplicate that procedure as many times as you have fields to check.



Back to Step 1 >>



Copyright 2000 by Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from http://www.thesitewizard.com/

+ Sniffers
+ Forms
+ Windows
+ 4x Browser
+ Images
+ Links
+ Frames
+ Clocks/Time
+ Misc.

Navigate

 Home
 Submit Script
 Tutorials
 Forums
 Link To Us
 Contact
 Tell A Friend
 Links
 Bookmark Us

  Sign up for our free, low volume email newsletter. Be notified when new free scripts are added.

 Email Address