By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

form field arrays

P: n/a

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

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[i].value = 4

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

thanks for any help.
*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hammy Hammy <ch***> writes:
I have a form with many textboxes. I have named them
"txt[1]", "txt[2]", "txt[3]", etc..

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[i].value = 4

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

Lasse Reichstein Nielsen - lr*
Art D'HTML: <URL:>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.