Home     Blog    Tutorials     Tips and Tricks     Script Library     Templates     Webmaster     Freelance jobs     Articles  

Javascript - Button examples
Alert button , Confirmation button , Image button , Next button , Previous button , Prompt button , Scrolling text button , Rotating text button

Javascript - Background
Background music , Background color/image , Fixed background image

Javascript - Cookies
Set cookie , get cookie

Javascript - Combo Boxes
combo with button , combo with out button , combo box & frame , Remote control combo , double combo , Combo remote control

Javascript - Form
 form validation, Check all checkboxes , uncheck all checkboxes , limit checkbox items selected , invert the selection of checkboxes , lock the checkbox , radio button links , set field value , Select the text from field

Javascript - Frames
Creating simple frame , Nested frames , Linking to another frame , Breaking frame , page opens in the same frame, page opens in a new window , loading multiple frames , using forms in frame , back and forward statements in frame , pop-up window and frames , inline frames(<iframe>
Javascript - Image
Image rollover , Change image , Text around image , Image button
Javascript - Links
Underline remover , Link description on status bar , hide link description on statusbar , Link description on a layer , Change link color on mouseover , Coloring links , Reload current page , Load the page on mouse over , view source code
Javascript - Meta tag
Using metatag , nocache ,Meta Redirect
Javascript - Statusbar
Default status , Changing message , flashing text , typing text , scrolling text , type in & scroll out , Link description on status , hide link description on status , colored scrollbar
Javascript - Table
Change table color on mouse over , Highlight a row , Move data from one column to another
Javascript - Text
Typing text , scrolling text , change text color ,Text style , Format text
Javascript - Window
Open new window , close the new window , create full window , close main window , scrolling up window , open pop up onload , six second delayed pop up, shaking window , popup window and frame, URL , browser checking , page forwarding , reload the current page
Javascript - Misc.
Ad rotater , copy data to clip board , view source code , metatag , nocache
Javascript Form Validation

Javascript Form Validation

Javascript FormValidator:
If you use  javascript to validate fields in a html Form, then here's a script that is extremely useful.

See for yourself -->


Advantages:
1> Validates Fields:Validates TEXT fields, SELECT fields, RADIO fields and TEXTAREA fields
2> Minimal coding: The script that validates the form is in a separate .js file and the script is very generic in nature.
You just have to add this file as an "include" file to your html file and add a couple of arrays
3> TEXTAREA Validation: TEXTAREA  fields are validated so that even if only carriage returns are entered into a TEXTAREA , validator will return an error message.
4> Customized Error messages: You can specify your error messages into an array. The validator takes care of the rest. no messy Coding!
 

How to use it?
Step 1:

    Download the javascript file(formvalidation.js) and place it in the same directory as your html file. Click here to Download javascript file(formvalidation.js)
Step 2:
    Add the following line under <head> of your html
    <SCRIPT SRC="formvalidation.js"> </script>
Step 3:
Now you have to define the field names that are to be validated. 3 arrays are used for this purpose.

Add following scriptlet under your <head> in your html and customize it as explained below:
<script>
ReqdFieldNames  = new Array("field1", "field2","field3", "field4");
FieldPrompts            = new Array("field1 Prompt", "field2  Prompt","field3  Prompt", "field4  Prompt");
FieldTypes               = new Array(SELECTFLD, TEXTFLD, RADIOFLD, TEXTAREAFLD)
</script>
 

ReqdFieldNames
All Fields that are to be validated should be to this Array. Replace  field1..., with your form field names (add only those that are to be validated).
Note: Javascript is case-sensitive. Please enter field names as you use in your HTML form
Eg:if you have 2 fields  Name and Age in a form to be validated the array would be:
ReqdFieldNames  = new Array("Name", "Age");

FieldPrompts:
Prompts for these fields. The validator uses these prompts when it finds an error.
Eg: FieldTypes  = new Array("Please enter Your Name", "Please enter Your Age");

FieldTypes:
Add the type of each fieldPrompts for these fields. The validator uses these prompts when it finds an error.
Enter Field Types into this Array.
For SELECT Fields use identifier --> SELECTFLD,
For Text Fields use identifier --> TEXTFLD
For Radio Fields use identifier --> RADIOFLD
For TEXTAREA Fields use identifier --> TEXTAREAFLD
Eg: FieldTypes               = new Array(TEXTFLD, TEXTFLD)
 
 


Step 4:

Modify your submit button as follows:
<INPUT TYPE=button onClick="if (ValidateForm() == true)
{
document.forms[0].submit()
}" VALUE="Submit">

That's it you are done! Good luck!

Hot XML Articles and Tips
Latest Random JavaScript Tips
Doc JavaScript's Tip of the Day Archive

A Sample Batch of Namespaces (5/20/2002)
Did you know there are thousands of classes in the .NET Framework? Get a glimpse of what's available for your JScript .NET code.
The hide Marker (6/13/2002)
Do you know the behavior difference between the override and the hide markers? Learn how to use the hide marker to avoid overriding.
Scripting Multiple Elements with the Same ID (9/21/2000)
Some applications require different elements with the same ID. Learn how to distinguish between them in your script.
Preserving White Spaces in XML (1/28/2002)
Do you know how to preserve white spaces in the input XML file? Learn how to load XML files and how to control their output format.
Loading XML from JavaScript (1/16/2002)
Do you know how to load an XML file from JavaScript in Internet Explorer? Learn how to create the DOMDocument object and how to print the XML data.
Privacy Enhancements in Internet Explorer 6 (7/21/2001)
Do you know what W3C's P3P WG is? Learn about the new privacy enhancements in IE6: better controlling of cookies.
Finding the File's Drive Letter (10/29/2000)
Ever wonder how to find a file drive letter? Learn about another property of the IE File object.
Splitting a String (9/25/2000)
Do you know of a quick way to explode a string? Let's look at how you can split a string.
The Screen Object (1/7/2000)
Do you know that Navigator reports a wider active screen area? Learn more about the differeneces between their screen objects.
Changing Frames (4/8/2000)
Do you know how to click a link and still not jump? Learn two different ways to implement such a link.
Navigator's vs Explorer's DHTML (2/12/2000)
Can you name the major differences between Netscape Navigator's and Internet Explorer's DHTML models? Learn why keeping a code browser-independent is not easy.
Extracting Information from the Error Object (9/20/2002)
Do you know how to get the error number and description from the Error object? Learn how to use the Error object to streamline your exception handling.
Stoping and Starting the IIS Server (4/15/2002)
Do you know how to stop and start the IIS server? It's a good practice to verify that the server is up.
Finding a File's Parent Folder (11/2/2000)
How do you find someone's parent without a family tree? Learn how to find a file's parent folder.
Bookmarklet Foundations (3/11/2000)
Have you tried using our bookmarklets? Learn how to use the javascript: construct.
pid=