469,323 Members | 1,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

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 1071
gits
5,390 Expert Mod 4TB
...
I even tried out this...
temp = Text + (looping variable);
document.form_name.temp.value
...
hi ... you've nearly got it ;) use the following:

Expand|Select|Wrap|Line Numbers
  1. document.form_name[temp].value
  2.  
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.