Getting form values with looped name insertions from the DOM?

B

Brian A

Let's say I have, in a form, the name 'firstName' .
eg. <input type="text" name="firstName" />
When the form is submitted I can get a value for this with syntax:-
fn=form.firstName.value;
This works. 'fn' gives the value of 'firstName', so no problem there.

However, it means that for every name in the form I have
to include a similar statement. I want to put this in a loop and feed
in different names. I can get them from the DOM.

Clearly it obviously isn't possible to do the following, though it
illustrates what I want to do.
x=firstName;
fn=form.x.value;
(where x replaces 'firstName')
So what method can I use?








---
Remove 'no_spam_' from email address.

Sign the petition to get High Definition TV via Freeview.
Get your friends to sign too!
Ofcom want to auction off the spectrum needed for Hi Def.
TV.
http://petitions.pm.gov.uk/High-Definition/
---
 
B

Brian A

Brian A said the following on 10/14/2007 5:34 PM:
Let's say I have, in a form, the name 'firstName' .
eg. <input type="text" name="firstName" />

Why do people keep trying to use XHTML on the web?
When the form is submitted I can get a value for this with syntax:-
fn=form.firstName.value;
This works. 'fn' gives the value of 'firstName', so no problem there.

"When the form is submitted"? Are you working on the server or the client? Client.
However, it means that for every name in the form I have
to include a similar statement. I want to put this in a loop and feed
in different names. I can get them from the DOM.

Clearly it obviously isn't possible to do the following, though it
illustrates what I want to do.
x=firstName;
fn=form.x.value;
(where x replaces 'firstName')
So what method can I use?

Assuming you are referring to client side, you use the elements collection:

form.elements[x].value
Thank you!!
That solves my problem.

---
Remove 'no_spam_' from email address.

Sign the petition to get High Definition TV via Freeview.
Get your friends to sign too!
Ofcom want to auction off the spectrum needed for Hi Def.
TV.
http://petitions.pm.gov.uk/High-Definition/
---
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top