Click to See Complete Forum and Search --> : Find the parent of an object?


krugos
07-10-2003, 06:58 AM
Hi I have the following HTML code:

<table name="bob">
<tr>
<td onclick="toggle(this,"checkboxname")>
Click here...
</td>
<td>
<input type="checkbox" name="checkboxname">
</td>
</tr>
</table>

and in my toggle (javascript function): I need to work out if the checkbox is checked, something like this...

if (this.parent.checkboxname.checked)

how do I do this? Basically I need to know how to find the parent of the object...


Regards,
Matt.

gil davis
07-10-2003, 08:10 AM
I don't think finding the parent of the TD object when you click is really what you want to do. The "parent" of the TD would be a TR.

In a W3C DOM-compliant browser, you would have to walk up the document tree until you find the FORM tag. Then you could find the checkbox.

The more direct approach would be to give the checkbox an ID and use document.getE;ementById("...") to find it directly, and don't bother using the "this" operator.