Hi all,
I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try....
in case you should see it later I apologize for posting the same question twice!
Here it is:
I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag.
I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the checked checkboxes and concatenate it.
Here is my Code:
<body>
<table border="1">
<tr>
<td class="listColu mn">
<span class="textItem ">Hello</span>
<input type="Checkbox" Id="ChBox">
</td>
</tr>
<tr>
<td class="listColu mn">
<span class="textItem ">Hej</span>
<input type="Checkbox" Id="ChBox">
</td>
</tr>
</table>
<script language="JavaS cript">
function getData(){
var values='';
for(i=0;i<docum ent.getElements ByTagName('inpu t').length;i++) {
var x = document.getEle mentsByTagName( 'input')[i];
var a = x.parentNode.ch ildNodes[1].nodeValue;
if (eval("x.checke d") == true) {
values=values+' &p_Sample='+ a;
}
}
document.write( values);
}
</script>
<input type="Button" value="Get Data" onclick="getDat a()">
</body>
If I run this example I get the following output:
&p_Sample=
Just as if the text were null.
I am pretty sure that I am pointing to the right object, because if I change "nodeValue" to nodeName I get "#text".
If I change my example, delete the <span> tags, and change "var a = x.parentNode.ch ildNodes[1].nodeValue; " to "var a = x.parentNode.ch ildNodes[0].nodeValue;
I get the expected result.
Could anybody help me understand why?
Thanks,
Anna
I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try....
in case you should see it later I apologize for posting the same question twice!
Here it is:
I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag.
I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the checked checkboxes and concatenate it.
Here is my Code:
<body>
<table border="1">
<tr>
<td class="listColu mn">
<span class="textItem ">Hello</span>
<input type="Checkbox" Id="ChBox">
</td>
</tr>
<tr>
<td class="listColu mn">
<span class="textItem ">Hej</span>
<input type="Checkbox" Id="ChBox">
</td>
</tr>
</table>
<script language="JavaS cript">
function getData(){
var values='';
for(i=0;i<docum ent.getElements ByTagName('inpu t').length;i++) {
var x = document.getEle mentsByTagName( 'input')[i];
var a = x.parentNode.ch ildNodes[1].nodeValue;
if (eval("x.checke d") == true) {
values=values+' &p_Sample='+ a;
}
}
document.write( values);
}
</script>
<input type="Button" value="Get Data" onclick="getDat a()">
</body>
If I run this example I get the following output:
&p_Sample=
Just as if the text were null.
I am pretty sure that I am pointing to the right object, because if I change "nodeValue" to nodeName I get "#text".
If I change my example, delete the <span> tags, and change "var a = x.parentNode.ch ildNodes[1].nodeValue; " to "var a = x.parentNode.ch ildNodes[0].nodeValue;
I get the expected result.
Could anybody help me understand why?
Thanks,
Anna
Comment