ne************@ hotmail.com said on 23/03/2006 1:00 AM AEST:
Rob,
Please quote what you are replying to - I posted two code snippets to be
used in different contexts. You may have used one in the other's
context. As you haven't quoted which bit you are replying to, I can't
tell what you are referring to.
Thanks for the response.
The essential reason that I posted the question was because I couldn't
figure out how to reference the checkbox from inside the onClick of the
radio button.
Unfortunately, the sample you posted (this.form.Chec kbox1) doesn't seem
to be working.
Are you sure that syntax is correct?
Yes, but it is not enough that that bit is correct. You need to either
quote what you are replying too or post the code that doesn't work.
A couple of tips: always ensure that your HTML is valid and that all
attribute values are quoted, even when not strictly necessary.
Consider the following forms (both tested in Firefox and IE):
<form name="form1" action=""
onclick="this.C heckbox1.checke d=this.Radio1[0].checked;">
<div>
<input type="radio" name="Radio1" value="Option1" >
<input type="radio" name="Radio1" value="Option2" >
<input type="checkbox" name="Checkbox1 ">
</div>
</form>
Note that when included in the onclick attribute of the form, 'this'
refers to the form so 'this.Checkbox1 ' refers to the checkbox. It is
equivalent to - document.forms['form1'].Checkbox1.
Note also that because there are two radio buttons named 'Radio1',
this.Radio1 returns a collection so to get the first one, I've used
this.Radio1[0].
Also note that I think it's pretty impractical, but serves for
demonstration purposes.
Now consider this version:
<form name="form1" action="">
<div>
<input type="radio" name="Radio1" value="Option1"
onclick="this.f orm.Checkbox1.c hecked=this.che cked;">
<input type="radio" name="Radio1" value="Option2" >
<input type="checkbox" name="Checkbox1 ">
</div>
</form>
Now 'this' refers to the radio button, not the form. So this.form
refers to the form attribute of the radio button, which is form1 and
this.form.Check box1 refers to Checkbox1.
Similarly, this.checked is the checked property of the radio button.
Also pretty useless in real life.
--
Rob