how can I get the position in the array of getElementsByName

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rubenhan
    New Member
    • Dec 2008
    • 7

    #1

    how can I get the position in the array of getElementsByName

    Hi,

    I have multiple text input fields with the same name "name[]" and "age[]" which will return an array of information when I get document.getEle mentByName("nam e[]") (should I use getElementsByNa me("name[]") instead?)

    For example,

    name[] age[]
    name[] age[]
    name[] age[]

    What I want to pull off is, when "name[]" goes onblur, a new set of empty fields will be added.
    Then, when "age[]" goes onblur, I want to add two more text fields like above but with the value of the previous name[] copied to the value of the new name[]. Here is an example.

    (john)name[] (14)age[]
    (john)name[] ()age[]

    In order to pull this off, I thought I have to somehow catch which position of the getElementByNam e("name[]") array it is and get that value and pass it to the onblur function in "age[]". How do I get that position? I'm assuming it's not item(). Is there a method that I could use?

    Thank you.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by rubenhan
    I have multiple text input fields with the same name "name[]" and "age[]" which will return an array of information when I get document.getEle mentByName("nam e[]") (should I use getElementsByNa me("name[]") instead?)
    you have to use getElementsByName() since getElementByNam e() doesn't exist.

    Comment

    • rubenhan
      New Member
      • Dec 2008
      • 7

      #3
      @Dormilich,

      Thank you. I'll use getElementsByNa me.

      Is there a method to find a current position of that array? In other words, is there a way to catch getElementsByNa me.item()?

      Should I just do

      Code:
      var j;
      var position = document.getElementsByName[j];

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        you access the elements from getElementsByna me() like your example. the name[] syntax is used to pass arrays to the server side form processing script (as far as I've understood this)

        regards

        Comment

        Working...