spacer
Yehuda Shiran September 30, 2001
Accessing a Collection Member
Tips: September 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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 document.forms[0] across the page:

<FORM METHOD="post" ACTION="mailto:tomer@internet.com"  
  ENCTYPE="text/plain" onSubmit="return proceedSubmission()">
<TEXTAREA NAME="inputField" COLS="40" ROWS="10"></TEXTAREA><BR>
<A HREF="thanks.htm" onClick="submitForm(0)">Mail It!</A>
</FORM>

<SCRIPT LANGUAGE="JavaScript">
<!--
function submitForm(sub) {
  document.forms[sub].submit();
}

function proceedSubmission() {
  return confirm("Click OK to mail this information");
}
// -->
</SCRIPT>

Mail It!
The second version below assigns ID="firstForm" to the first element and accesses it through forms["firstForm"]:

<FORM METHOD="post" ACTION="mailto:tomer@internet.com"  
  ENCTYPE="text/plain" onSubmit="return proceedSubmission()" ID="firstForm" >
<TEXTAREA NAME="inputField" COLS="40" ROWS="10"></TEXTAREA><BR>
<A HREF="thanks.htm" onClick="submitForm('firstForm')">Mail It!</A>
</FORM>

<SCRIPT LANGUAGE="JavaScript">
<!--
function submitForm(sub) {
  document.forms[sub].submit();
}

function proceedSubmission() {
  return confirm("Click OK to mail this information");
}
// -->
</SCRIPT>
Try it:


Mail It!

People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger