spacer
Yehuda Shiran August 11, 2000
Cross-Element Referencing via a Back Door
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Back-door referencing allows you to access a form from its descendent elements. The form property enables this back-door access. When you send the object this to an event handling function, the ancestor form object cannot be restored, unless you use the back-door form property of the element. The following example demonstrates this concept. When you click the button, the button's object (this) is sent to the event handling function. This function accesses the second element of the form (text field) through the back-door form property, and prints out the text entry currently displayed in the entry field. Here are the button and the text entry field:

Here is the script and HTML segment that implement the above demo:

<SCRIPT LANGUAGE="JavaScript">
<!--

function getValue(otherElement) {
  alert(otherElement.form.elements[1].value);
}

// -->
</SCRIPT>
<FORM>
<INPUT TYPE="button" VALUE="click me" onClick="getValue(this)">
<INPUT TYPE="text" VALUE="Have you checked our latest tools?" SIZE=30>
</FORM>


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business