www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Accessing array named form fields

  1. #16
    Join Date
    Mar 2010
    Posts
    14
    Well, since it doesn't give you a unique ID/name (if you use array named form fields), you can't use getElementByName/ID on the resulting child.

    Even more so, the previous/nextsibling method doesn't work on input fields that are inside previous/next table cells...I can't source this statement, but that's what happens when I put the form fields in table cells. You can just take the last example and put <tr><td> between fields. Bam, suddenly the function fails.

  2. #17
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Most DOM references will fail if you change the html.
    What is the real html you are using?

  3. #18
    Join Date
    Mar 2010
    Posts
    14
    If I put the previous HTML inside a table:
    Code:
    <table><tr><td><form method="post"></td></tr>
    <tr><td><input type=checkbox name=check[] onclick="bla(this)"></td></tr>
    <tr><td><input type=text name=input1[] value=bla1></td></tr>
    <tr><td><input type=checkbox name=check[] onclick="bla(this, true, 2)"></td></tr>
    <tr><td><input type=text name=input1[] value=bla2></td></tr>
    <tr><td><input type=text name=input1[] value=bla3></td></tr>
    <tr><td><input type=checkbox name=check[] onclick="bla(this, false, 2)"></td></tr>
    <tr><td><input type=text name=input1[] value=bla4></td></tr>
    <tr><td><input type=checkbox name=check[] onclick="bla(this, false, 2)"></td></tr>
    <tr><td></form></td></tr></table>
    Then function bla would fail.

  4. #19
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    function bla(test) {
    var list = test.parentNode.parentNode.parentNode.getElementsByTagName('input');
    for(var i=0; i<list.length; i++) {
        if(list[i]==test) {
            list[i+1].value='foobar';
            break;
            }
        }
    }
    The form tags should be outside the table.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles