form field arrays

Discussion in 'Javascript' started by Hammy Hammy, Sep 17, 2003.

  1. Hammy Hammy

    Hammy Hammy Guest

    Hi all,

    I have a form with many textboxes. I have named them
    "txt[1]", "txt[2]", "txt[3]", etc..

    I did this so that I could easily loop through them and get their
    values.

    However, how do I assign a value to one of these fields inside a loop?

    For example:

    for (i=1; i<=10; i++){
    document.frmA.txt.value = 4
    }

    This gives me an error message.
    I don't want to use 'document.frmA.elements.value because I have
    other textfields on this page and the elementID doesn't always match.

    thanks for any help.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Hammy Hammy, Sep 17, 2003
    #1
    1. Advertising

  2. Hammy Hammy <> writes:

    > I have a form with many textboxes. I have named them
    > "txt[1]", "txt[2]", "txt[3]", etc..


    <URL:http://jibbering.com/faq/#FAQ4_25>

    Bad idea. "[" and "]" are not legal in HTML ids/names.

    It would be better to call them "txt_1", "txt_2" etc.
    It also prevents you from getting confuzed.

    > document.frmA.txt.value = 4


    document.forms['frmA'].elements['txt_'+i].value = 4;

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Sep 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philipp
    Replies:
    21
    Views:
    1,160
    Philipp
    Jan 20, 2009
  2. NotGiven
    Replies:
    3
    Views:
    372
    Michael D. Kersey
    May 13, 2004
  3. GavMc
    Replies:
    4
    Views:
    361
    Evertjan.
    Sep 22, 2005
  4. NotGiven
    Replies:
    3
    Views:
    318
    Michael D. Kersey
    May 13, 2004
  5. Sound
    Replies:
    2
    Views:
    466
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page