Getting parent id of radio button or a check box

4287
1
Jump to solution
05-09-2012 08:39 AM
SamirGambhir
Occasional Contributor III
Hi,
I am trying to get the parent id of the selected radio button or checked check box. I am using ArcGIS 10.0 with JavaScript API.
My button/check box are nested in a div. Is it possible to get the id of each level of parentNode?  e.g.
<div id"someDivId">
<table id="someTableId">
<tr id="someTRId">
<td id="someTDId">myTd</td>
<td><input data-dojo-type="dijit.form.RadioButton" id="checkTDId" /></td>
</tr>
</table>
</div>

Also, once the radio button is selected, how do I get the id and/or the displayed value of the sibling td?
Thanks for your help,
Samir
0 Kudos
1 Solution

Accepted Solutions
SamirGambhir
Occasional Contributor III
I found a solution to this problem and I am posting it here:

var myElem = dojo.byId(myId) //provides access to the element itself
myElem.parentNode //provides access to the "input" element in the example I provided
myElem.parentNode.parentNode //provides access to the parent "td" element in the example
myElem.parentNode.parentNode.parentNode //provides access to the parent "tr" element
myElem.parentNode.parentNode.parentNode.id //provides the id of the parent "tr" node
myElem.parentNode.parentNode.parentNode.getElementsByTagName("td") //provides access to all "td" child elements under the parent "tr" element

I can use this control to get the innerHTML of the first child element. The overall code is as follows:

function returnParentId(myId){
var myElem = dojo.byId(myId).parentNode.parentNode.parentNode.getElementsByTagName("td");
myIndValue = myElem[0].innerHTML;
return myIndValue;
}

I hope this is helpful.
Thanks
Samir

View solution in original post

0 Kudos
1 Reply
SamirGambhir
Occasional Contributor III
I found a solution to this problem and I am posting it here:

var myElem = dojo.byId(myId) //provides access to the element itself
myElem.parentNode //provides access to the "input" element in the example I provided
myElem.parentNode.parentNode //provides access to the parent "td" element in the example
myElem.parentNode.parentNode.parentNode //provides access to the parent "tr" element
myElem.parentNode.parentNode.parentNode.id //provides the id of the parent "tr" node
myElem.parentNode.parentNode.parentNode.getElementsByTagName("td") //provides access to all "td" child elements under the parent "tr" element

I can use this control to get the innerHTML of the first child element. The overall code is as follows:

function returnParentId(myId){
var myElem = dojo.byId(myId).parentNode.parentNode.parentNode.getElementsByTagName("td");
myIndValue = myElem[0].innerHTML;
return myIndValue;
}

I hope this is helpful.
Thanks
Samir
0 Kudos