Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Client-side Validation with Javascript

By Steve Adcock
2005-05-14


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


Tutorial Pages:
» Client-side text field validation with Javascript
» Calling the appropriate form
» Amazing Javascript error checking
» Putting it all together


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function