Having array in forms?

Discussion in 'JavaScript' started by mahmood, May 14, 2007.

  1. #1
    If I want to have arrays in a form I do something like this:
    <input type='hidden' name='myName' value='something'/>
    <input type='hidden' name='myName' value='something'/>
    PHP:
    So I can get the value of tags by document.formName.myName[0].value.

    But since I need to read the data through php after submitting the form I have to change it to name='myName[]'.

    Question: how do I get the value of myName now? This time document.formName.myName[0].value wouldn't work.
     
    mahmood, May 14, 2007 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    document.formName.elements["myName[]"] returns the array.
    each element can then be accessed as usual.
    e.g.: document.formName.elements["myName[]"][0].value
     
    phper, May 14, 2007 IP
    mahmood likes this.
  3. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Great, thank. I'm going to try it.
     
    mahmood, May 15, 2007 IP