August 7, 2000 - Back-Door Referencing of the Form Object
August 7, 2000|
Back-Door Referencing of the Form Object
Tips: August 2000
Yehuda Shiran, Ph.D.
thisobject. Here is a text field that turns into "thank you" once you change its "email..." string (click outside the field to signal the change's end):
Here is the script that implements this field:
this.form is equal to
callingElement.elements.value is equal to the full path:
Every form element includes a
form property which enables a reverse access; that is, ability to reach the form from its elements (although the element is really the form's property). Therefore, you can use any one of the following expressions to access the first element of the first form in a given document:
document.forms.elements document.forms.elements.form.elements document.forms.elements.form.elements.form.elements
You will probably never use this property independently in a script, because you can always refer to a form directly as a property of the window's
document object. However, such a reference is used a lot with forms, because an event handler's script references the event handler as
this, and the
form property enables you to reference the form through a back door.