Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Getting form values with looped name insertions from the DOM? (http://www.velocityreviews.com/forums/t933203-getting-form-values-with-looped-name-insertions-from-the-dom.html)

Brian A 10-14-2007 09:34 PM

Getting form values with looped name insertions from the DOM?
 
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/
---

Brian A 10-15-2007 10:47 AM

Re: Getting form values with looped name insertions from the DOM?
 
On Sun, 14 Oct 2007 19:39:30 -0400, Randy Webb
<HikksNotAtHome@aol.com> wrote:

>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/
---


All times are GMT. The time now is 09:18 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.