form field arrays

H

Hammy Hammy

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.
 
L

Lasse Reichstein Nielsen

Hammy Hammy said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top