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

Formatting Numbers (5/5/2000)
Do you know that IE 5.5 may simplify your code? Learn about its new built-in number formatting capabilities: toFixed(), toPrecision(), and toExponential().
Appending DOM Strings (1/27/2001)
Do you know how to append a string to text node data? Learn how to assemble a text node by concatenation.
Defining Polymorphism (6/23/2002)
What are the three cornerstones of object oriented programming languages? Learn about the third foundation: polymorphism.
The WSDL's service Element (11/12/2001)
Do you know how many port elements a Web service has? Learn how to define the service element in the Web service description file.
JavaScript's Object Types (3/6/2001)
What's the difference between Math, window, and employee? Learn about JavaScript's three types of objects.
IBuySpy's Color-Coded Folder Map (9/26/2002)
Do you know which files go where in IBuySpy Store directory? Here is a color-coded map of the directory structure.
Installing IIS (4/14/2002)
Do you know how to install the Internet Information Services (IIS) server on your PC? Here is a quick manual.
Detecting An Event within A Page (10/10/2001)
Do you know how to handle the same event for a group of objects? Learn how to attach an event handler to the containing page, and how to find the source object.
Using Microsoft Print Template Loader (8/31/2001)
Do you know that templatePrinter is accessible from C++ only? Learn how to use a Microsoft executable to load print templates.
A Name Tracker (2/20/2000)
Have you ever wanted to remember a user's name, right? Here's how to do it with JavaScript cookies.
The recalc() Method (8/8/2000)
Do you know how to force an evaluation of all dynamic properties? Learn how to use the recalc() method.
Locating the Error Origin (12/19/2001)
Do you know how to debug an error when calling a Web service in Internet Explorer? Learn how to use the code property of the errorDetail object to locate the culprit.
Parent-Last-Child Synchronization (11/12/2000)
What's the difference between waiting for the last child or waiting for all children? Learn about the last option to synchronize with in HTML+TIME.
Validating DOMDocument Upon Request (2/25/2002)
Do you know how to recheck your DOMDocument after manipulating it? Learn how to validate the DOMDocument tree whenever you need to.
Moving Objects Vertically (12/12/2000)
Is moving objects down as easy as moving them horizontally? Learn how to move objects vertically, independent of the browser.
pid=