473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 1118
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

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

Similar topics

16
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an...
4
by: gigal | last post by:
For some "new" created objects of class A with pointers, how to put them into a list, list<class A> l? p1 = new A(); p2 = new A(); P3 = new A(); .... Thank you very much!
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
5
by: vivekian | last post by:
Have to create a linked list of objects of the same type based on user input. The number of objects in the list is dynamic depending on the number input from the user. What would be the best way to...
8
by: Cuthbert | last post by:
Hi folks, This question is a little deep into memory management of microprocessor. How do we know the memory arrangement using in microprocessors? Top-Bottom or Bottom-Top? For example, the...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
5
by: Rolf Mander | last post by:
Hi, I need to use dynamic variable names but for objects. As you know something like that works fine: $variable="content"; $part="able"; echo ${"vari".$part}; // gives out content but i...
4
by: David d'Angers | last post by:
hi all i need a function that returns all the file names contained in a directory since the number of files is not known in advance how should i go about to use "dynamic array" to hold the file...
18
by: Angus | last post by:
Hello We have a lot of C++ code. And we need to now create a library which can be used from C and C++. Given that we have a lot of C++ code using classes how can we 'hide' the fact that it is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.