|
September 30, 2001 Accessing a Collection Member Tips: September 2001
Yehuda Shiran, Ph.D.
|
|
There are several ways to access a collection member on a page. One way is via its index. If you know the positional order of the element on the page, you can access its corresponding collection member via the index. The other way to reference a collection member is by its ID. In this case you need to label the element with an ID. Let's take an example. The first form on a page can be referenced as document.forms[0]. If its ID is "firstForm", the form can be accessed as document.forms["firstForm"].
The following piece of code sends me a mail with your free text. The first version below assumes that the form is no. 1 on the page. Thus, it can be referenced as
The second version below assigns ID="firstForm" to the first element and accesses it through forms["firstForm"]:
Try it:
People who read this tip also read these tips: Look for similar tips by subject: |