Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    nextSibling problem in a form

    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

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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);
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •