In the following table segment, I have been trying to use DOM techniques to get the text values.
For example in this line: (<span id=“edit5_oname” >BOBBY</span>), I only want to get BOBBY.
What’s happing is if I use alert(x[2].innerHTML); it returns <span id=“edit5_ownerid”>8</span>.
I have tryed various techniques like:
alert(x[2].data);
alert(x[2].innerHTML);
alert(x[2].firstChild.nodeValue);
alert(x[2].firstChild.firstChild.nodeValue);
Also various:
parentNode
lastChild
nextSibling
offsetParent
previousSibling
Some of these return an alert with nothing, others return undefined.
Normally when there is no span involved the alert(x[2].firstChild.nodeValue); works everytime.
Does anyone know the correct technique to pluck out just the text? Thanks
Whole table not shown:
<tr valign="top" id="a1" onclick="cell(this.id)">
<td align="left" class="listIcons" valign="middle" nowrap="nowrap">
<a href='olookup_edit.php?editid1=8' id="editlink5" title="Edit"><img class="listIcon" src="images/icon_edit_new.gif" align="middle" alt="Edit" border="0"></a>
</td>
<td align="left" valign="middle" width="20" >
<input type="checkbox" name="selection[]" value="8" id="check1_5">
</td>
<td valign="middle" align="right">
<span id="edit5_ownerid" >8</span>
</td>
<td valign="middle" align="left">
<span id="edit5_oname" >BOBBY</span>
</td>
<td valign="middle" align="left">
<span id="edit5_ostreet" >B WAY</span>
</td>
</tr>
Here is the js function:
<script type="text/javascript">
function cell(id)
{
var x=document.getElementById('maintable').rows[id].cells;
alert(x[2].innerHTML);
//opener.document.editform1.display_value_ownerid_1.value = x[1].firstChild.nodeValue;
//opener.document.editform1.display_value_petowner_1.value = x[2].firstChild.nodeValue;
//opener.document.editform1.display_value_ostreet_1.value = x[3].firstChild.nodeValue;
self.close();
}