"Sarah West" <ab*@hotmail.com> wrote in message
news:3f**********************@news.optusnet.com.au ...
I'm curious as to how it works?box.form.name.value=defaultValue.name
The name of my form is 'form1', and the name of my checkbox
is called 'checkbox', how can you refer to it in such generic
terms eg 'box.form.<element>.<value>'?
box is a reference to a form element (the checkbox, the - this - object
within the onclick event handling method) and all form elements have a
property with the name "form" that is a reference to the form that
contains them.
So the onclick function passes the - setDefaults - function a reference
to the checkbox as - this -, the function receives that reference as
ts - box - parameter and can then refer to the containing form as -
box.form -, and can use that reference to the form exactly as it may use
any other reference to a form such as - document.forms['form1'] - .
Incidentally, "name" is not a good name for a form element as the form
object already has a property with the name "name" which holds the
string value provided in the HTML NAME attribute for the form ("form1").
Creating an element with the name "name" will result in the expected
string "name" property of the form being replaced with the reference to
the element. That is not a problem in this case as none of your code is
interested in the (original string) "name" property of the form, but
giving form elements NAME (or ID) attributes that correspond with
existing form element named properties is a habit that will eventually
come back and kick you. JavaScript is case sensitive and form property
names are entirely initial lower case so something as simple as always
making form element NAME attributes have initial capitals would be
sufficient to avoid any naming conflicts within the form.
Richard.