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

The SqlDataReader Class (10/12/2002)
Do you know how to ensure that all records are read from a database? Learn about the roles and responsibilities of the SqlDataReader class.
Checking for an Enumerable Property (3/12/2001)
How do you find out whether a property is enumerable? Learn how to create and check for enumerable properties.
Cookies (1/16/2000)
Have you practiced cookie baking lately? Learn how to create cookies in JavaScript.
The Implementation Type (1/18/2001)
Is your document XML-based or DOM-based? Learn how to query the implementation type in Netscape 6.
Calling the add Web Service from DHTML (7/12/2002)
Do you know how to write a GUI for consuming a Web service from a DHTML page? Here's how to call the add Web service.
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 LayoutRect's Overflow (9/14/2001)
Do you know how to detect page overflow in a print template? Learn how to use the LAYOUTRECT's event handlers and properties to distinguish between page completion and page overflow.
Checking for a Certain Property (3/10/2001)
What's the easiest way to check for a certain property's existence? Learn how to get immediate feedback without iterating over all properties.
The Personal Bar (7/25/2001)
Where do you get your stock ticker from, E*TRADE or PaineWebber? Learn how to get this and other information from Internet Explorer 6's Personal Bar.
Retrieving Objects (12/25/2000)
What's your most difficult habit to overcome when writing script for Netscape 6? Learn how Netsape 6 has stricter protocols than Internet Explorer.
JScript .NET's Strong Typing (4/23/2002)
Do you know what a strongly-typed language is? Learn about some of the benefits in JScript .NET's optional variable typing.
Creating A Master Page (8/2/2001)
Do you know how to create a master page? Learn how to specify the style of a background page with DeviceRect.
Stopping a Scroller (4/25/2000)
Do you know how to stop a scroller when stepping over it? Learn how to use the onmouseover event handler.
Resolving Style Conflicts (7/5/2000)
What happens when you have conflicting style specifications? It depends on whether it is STYLE vs. STYLE or STYLE vs. element attribute.
Overlapping Frames (2/7/2001)
Do you know how to stack up frames? Learn how to overlap frames with the new IFRAME tag in Internet Explorer 5.5 and Netscape 6.
pid=