Core JavaScript 1.5 Guide:Creating New Objects:Using this for Object References
From MDC
[edit] Using this for Object References
JavaScript has a special keyword, this, that you can use within a method to refer to the current object. For example, suppose you have a function called validate that validates an object's value property, given the object and the high and low values:
function validate(obj, lowval, hival) {
if ((obj.value < lowval) || (obj.value > hival))
alert("Invalid Value!");
}
Then, you could call validate in each form element's onchange event handler, using this to pass it the form element, as in the following example:
<input type="text" name="age" size="3" onChange="validate(this, 18, 99)">
In general, this refers to the calling object in a method.
When combined with the form property, this can refer to the current object's parent form. In the following example, the form myForm contains a Text object and a button. When the user clicks the button, the value of the Text object is set to the form's name. The button's onclick event handler uses this.form to refer to the parent form, myForm.
<form name="myForm">
<p><label>Form name:<input type="text" name="text1" value="Beluga"></label>
<p><input name="button1" type="button" value="Show Form Name"
onclick="this.form.text1.value=this.form.name">
</p>
</form>