471,858 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,858 software developers and data experts.

Using dynamic names for objects in JS

Hi everyone!
I am an amateur JS programmer and I am stuck at a point. I would be glad if someone suggests me a solution. The problem goes like this...

I have a set of textboxes, who's names I am assigning as "Text1", "Text2" and so on with the help of a loop (using the setAttribute feature).

Now, at the time of submitting the information to the server, I need to validate the fields. If I'd kept the name say "Text", then I can access it as document.form_name.Text.value. In my case, how can i access the textbox object's value, whose name is dynamically changing ?

I even tried out this...
temp = Text + (looping variable);
document.form_name.temp.value....But it doesn't work..!! I am almost on the verge of completion of my project...I am stuck here...Could anyone please suggest me a solution..?

Thanks in advance.
Jun 8 '07 #1
1 1091
5,390 Expert Mod 4TB
I even tried out this...
temp = Text + (looping variable);
hi ... you've nearly got it ;) use the following:

Expand|Select|Wrap|Line Numbers
  1. document.form_name[temp].value
kind regards ...

ps: explaination is, that with the . you refer a property but you would refer a property named 'temp' ... so you have to use the array-like reference when refering a property that is variable
Jun 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by Suzanne Vogel | last post: by
4 posts views Thread by gigal | last post: by
13 posts views Thread by Stumped and Confused | last post: by
23 posts views Thread by Russ Chinoy | last post: by
5 posts views Thread by vivekian | last post: by
5 posts views Thread by Rolf Mander | last post: by
4 posts views Thread by David d'Angers | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.