multidimensional name-attribute and javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan

    multidimensional name-attribute and javascript

    In my HTML forms (created by PHP) for attribute
    names I have been using multidimensiona l arrays as illustrated
    in the following:

    <table>
    <tr>
    <td> ID </td>
    <td> [1661] <input TYPE=hidden Name=frm_s[0][0] Value=1661></td>
    <td> [1662] <input TYPE=hidden Name=frm_s[1][0] Value=1662></td>
    <td> [1663] <input TYPE=hidden Name=frm_s[2][0] Value=1663></td>
    </tr>
    <tr>
    <td> Name </td>
    <td><input TYPE=text NAME=frm_s[0][1] ></td>
    <td><input TYPE=text NAME=frm_s[1][1] ></td>
    <td><input TYPE=text NAME=frm_s[2][1] ></td>
    </tr>
    <tr>
    <td> Address </td>
    <td><input TYPE=text NAME=frm_s[0][1] ></td>
    <td><input TYPE=text NAME=frm_s[1][1] ></td>
    <td><input TYPE=text NAME=frm_s[2][1] ></td>
    </tr>
    </table>

    and PHP can deal with these multidimensiona l attributes as
    multidimensiona l variables. However, I find the need to
    deal with user input in these forms on the client side and
    I cannot figure out how to access such variable names in
    javascript.

    Has anyone any ideas?

    Thank you for your time.

  • Martin Honnen

    #2
    Re: multidimensiona l name-attribute and javascript



    Ivan wrote:
    [color=blue]
    > In my HTML forms (created by PHP) for attribute
    > names I have been using multidimensiona l arrays as illustrated
    > in the following:
    >
    > <table>
    > <tr>
    > <td> ID </td>
    > <td> [1661] <input TYPE=hidden Name=frm_s[0][0] Value=1661></td>
    > <td> [1662] <input TYPE=hidden Name=frm_s[1][0] Value=1662></td>
    > <td> [1663] <input TYPE=hidden Name=frm_s[2][0] Value=1663></td>[/color]

    Whatever name you use in HTML, with JavaScript you use
    document.forms['formname'].elements['elementname']
    to access the control object e.g.
    document.forms['formname'].elements['frm_s[0][0]']
    Instead of using a string literal inside of the square brackets you can
    of course use any Javascript expression constructing that string e.g.
    with loop variables i and j
    document.forms['formname'].elements['frm_s[' + i + '][' + j + ']']
    --

    Martin Honnen


    Comment

    • Ivan

      #3
      Re: multidimensiona l name-attribute and javascript



      Martin Honnen wrote:[color=blue]
      >
      > Whatever name you use in HTML, with JavaScript you use
      > document.forms['formname'].elements['elementname']
      > to access the control object e.g.
      > document.forms['formname'].elements['frm_s[0][0]']
      > Instead of using a string literal inside of the square brackets you can
      > of course use any Javascript expression constructing that string e.g.
      > with loop variables i and j
      > document.forms['formname'].elements['frm_s[' + i + '][' + j + ']'][/color]

      Thanks!!

      Comment

      Working...