HTML and CSS Reference
Figure 11.21 The user clicked the Reset Form button. The dialog box confirms the
choice before the input boxes are reset to their default values.
The this keyword is especially helpful when dealing with forms. We used the this word
when working with objects as a reference to the current object. For forms containing
multiple objects, such as checkboxes, radio buttons, and textboxes, it is easier to refer
to the object with the this keyword than by using its full name when calling a function.
When using an event handler, the this keyword always refers to the object that trig-
gered the event. If the event is triggered from within the <form> tag, this refers to the
current form, but if it is triggered by an element within the form, such as an input device,
then it references that element. Each element has a form property that references the
form in which it was created. In the following segment of an HTML document, note that
when the onClick event handler is triggered within the first button input type, the form
property is used to reference the form itself, whereas in the second button, the this key-
word refers to the current button.
value="Print Form Stuff"
onClick="display_formval(this.form);" /> <-- this keyword references the
form object by using the
element's form property
value="Print Button Stuff"
onClick="display_buttonval(this) ;" />
<-- this keyword references the
current object, the button