codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » Javascript » Article

A Simple Form Validation Script

Article by: Syed Zulfi (5/19/2003)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: A Simple Javascript function which validates the data in the html forms.
Viewed: 77602 times Rating (38 votes): 
 3.4 out of 5
 Rate this Article  Read Comments  Post Comments

A Simple Form Validation Script



The Javascript Form Object Properties and Methods can be used to Validate the Html Form.The Multiple Forms in the Html Page are Held as Forms Array.The Javascript Forms Array also holds Information about each Object within the Form tag.

Select All Code


The Multiple Forms in the Html page can be accessed by refering to its Array Index. document.forms[0] refers to the First Form in the Html Page.Similarly the Elements within the Form Tag can be accessed by refering to the elements Array Index. document.forms[0].elements[0] refers to the First element in the First Form in the Html Page.
In the Above Example,the function 'validateForm()' has two loops.The first loop runs thru all the elements in the form and if it encounters any empty elements it append the field name to the message.The Second loop runs thru all the form elements and alerts the user to fill the empty field.




CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'A Simple Form Validation Script'
Posted by :  Archive Import (jeelani shaik) at 13:13 on Saturday, May 24, 2003
great script buddy...
keep coding
Posted by :  Archive Import (Agnes) at 23:54 on Sunday, August 03, 2003
yeah ... really simple ... but can't validate the values e.g. email validation ...
Posted by :  Archive Import (paul) at 18:31 on Wednesday, August 20, 2003
wikkid script i would like something like this :)
Posted by :  Archive Import (javadym) at 07:14 on Sunday, September 07, 2003
Hello

I'am software engineering

and Like javaScript Programing

Please send me Simple javascript that

insert and update to xml file

Tanks.
Posted by :  apurva_007 at 01:00 on Thursday, March 11, 2004
nice script.. keep up the good work
Posted by :  pixelhub at 08:38 on Tuesday, April 13, 2004
Hi

is there any way i can skip a field(s) from being checked.

thanks
Posted by :  rubyarasi at 05:19 on Friday, September 29, 2006
Hi,
I am an engineering student doing my project in Jsp...
Could you please send me the jsp code to connect the textfields in a form to the database(Ms-Access)..
Posted by :  cg at 10:25 on Monday, June 18, 2007
is there any way i can skip a field(s) from being checked?
Posted by :  SweetKillerBunny at 15:38 on Wednesday, September 30, 2009
This helped me with a problem I had validating a form.

Thanks.
Posted by :  nancy16788 at 09:41 on Wednesday, October 07, 2009
hi,
i am doing a casestudy on "Birds is different countries".i have created a text box and if i give a bird name it must display the page in which it contains the details of the bird.....i need an idea of how validation can be done using javascript.

thank you.


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
Javascript - Enable and Disable form elements
by Jeff Anderson
This is a relatively little known and under-used feature of javascript which can be very useful in guiding a user through a form. Using the disabled tag, you can switch on and off elements in a form.
Check IsNumeric Function
by Jeff Anderson
A javascript validation function to check whether the details entered by a user are numeric.
Javascript Onload Event
by Jeff Anderson
Sometimes you need to perform an action immediatley after the page has loaded. That's when the onLoad Event Handler comes in handy
Form Validation Function
by Jeff Anderson
A javascript validation function that you can use to validate all types of forms.
JavaScript Field Is Empty Form Validation
by Jeff Anderson
This javascript function allows you to check whether a form field has been completed or not.
Javascript Get Selected Text
by Jeff Anderson
A cross-browser script to get text selected by the user
Check Email Validation Function
by Jeff Anderson
A javascript validation function to check whether the user has entered a valid email address in a form.
Multiple submit buttons on a single form
by Kiran Pai
This script shows you how to submit the contents of a form to different programs depending on which Submit button you press. Additionally it also shows how to call two different functions when you press the Submit button.
Validate Form and Disable Submit Button
by Marylou Marks
I have a form that validates info, but I also want to disable the submit button. The disable part worked before adding the form validating.
Javascript onUnload Event Handler
by Jeff Anderson
The onUnload Event Handler allows you to perform an action as the user leaves the page.








Recent Forum Threads
• C++
• Re: refresh parent after closing pop up window
• Dynamic Insertion
• Date and Time function around the world???
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009