...

View Full Version : nextSibling problem in a form



umen
08-22-2002, 08:23 PM
Hello i have simple form something like that:
---------------------------------------------------
<form name="myFrom">
<table>
<tr>
<td><input type=text name=foo1></td><td>name</td>
</tr>
<tr>
<td><input type=text name=foo2></td><td>last name</td>
</tr>
<tr>
<td><input type=text name=foo3></td><td>email </td>
</tr>
</table>
</form>
---------------------------------------------------
now im trying by script to get the innerTEXT from the next <td> after every input
something like :
----------------------------------------------------
for(var i=0;i<myFrom.elements.length;i++)
{
alert(MyForm.elements(i).nextSibling.innerTEXT);
}
----------------------------------------------------
but im getting run time error
what is wrong here?

tanks

jkd
08-22-2002, 08:33 PM
elements is an array (uses [] syntax), not a method ( () syntax).

Also, the property is innerText, not innerTEXT, and is IE-only. Also, nextSibling is undefined for the form elements, since they are the only child. The td is want is the nextSibling to the parentNode td cell that contains the input.

You could accomplish it according to W3C DOM via:
[code]
for(var i = 0; i < myForm.elements.length; i++) {
alert(myForm.elements[i].parentNode.nextSibling.firstChild.nodeValue);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum