iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 3, 2008
Poll: Which Web editor do you use?
About
 
July 3, 2008
Book Review: Head First JavaScript
WebReference.com
 
July 3, 2008
10 Things You Can Do With a Wiki
About
 
July 2, 2008
Web Host Reviews - 10 New Reviews
About
 
July 2, 2008
14 Reasons You Should Join a Social Network
About
 
July 1, 2008
Mark Boulton's Freelance Design Secrets
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

Client-side text field validation with Javascript 

  Views:    25871
  Votes:    11
by Steve Adcock 4/30/04 Rating: 

Synopsis:

Javascript is as powerful as any client-side language comes, and text field validation is a tremendously desired capability many webmasters want for their forms. Let's take a look at a little javascript for the purpose of validating feedback forms.
Pages: firstback2 3 forwardlast
The Article

I will admit that I am not a huge fan of client-side scripting (for the exception of HTML, of course) because of its relatively low power and compatibility between browsers. Javascript, however, is as powerful as any client-side language comes, and text field validation is a tremendously desired capability many webmasters want for their forms, and without server-side languages (or at least knowledge of them), Javascript is relied upon very heavily.

Calling the appropriate form

Javascript allows for a couple different calls to document forms, either by the name or by the position of the form within the document relative to other forms, beginning at 0. For example, if an HTML document contains 2 forms, the first form would be called as follows:

document.forms[0]

For those familiar with arrays, this will come fairly clearly to you. Javascript will build the number of forms into an array, called forms. Arrays always begin at 0, so to figure out the actual array value of the form, take the forms position on the page, relative to other forms, and subtract one. The 5th form, for example, would be called like this:

document.forms[4]

If you provide your HTML forms names, the name of the form can also be used and will be easier for many webmasters. Simply replace the position of forms[x] with the form name. For example, if a form's name was 'feedback', calling that specific form within the document would be written like this:

document.feedback

Pages: firstback2 3 forwardlast

Similar/related articles:


 
  Sponsors