473,598 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using dynamic names for objects in JS

3 New Member
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_n ame.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_n ame.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 1131
gits
5,390 Recognized Expert Moderator Expert
...
I even tried out this...
temp = Text + (looping variable);
document.form_n ame.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
2663
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 option. Let's call the id of a class "cid" (for "class id"). The function signature should look like this: ******************************************
4
1448
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
9603
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
23
19156
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
1937
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 name these objects ? Thanks, vivekian
8
1998
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 "Top-Bottom" is arranging memory resource from higher address to lower address.
7
8212
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
5066
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 need to use a database object after a mysql query something like that
4
1582
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 names ? can anyone post some code snippets please? thanks
18
2282
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 C++ from C compilers? Can we have a C header file which uses the functionality of the C++ files and compile this into a lib file?
0
7992
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2414
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1505
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.