Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Expressions 1

Status
Not open for further replies.

Jww193

Programmer
Apr 8, 2003
7
US
Hey All,

Is there any way to dynamiclly reference form variables such as: Name1,Name2,Name3 etc.,??

Most languages have dynamic expressions but i can't find anything in JS that is comparable. I have a bunch of occuring fields and related occuring fields that i want to validate using JS.

So if i could reference them like, Name + idx="something", where idx is a numeric variable it would be great.
 
there's two ways i know of:
[tt]
var name = "someName";
for (var x = 0; x < 10; x++) {
var tmp = document.form[0][name + x].value;
}[/tt]

or
[tt]
var name = &quot;someName&quot;;
for (var x = 0; x < 10; x++) {
var tmp = eval(&quot;document.form[0].&quot; + name + x + &quot;.value;&quot;);
}[/tt]


the first method will be faster, as it doesn't have to invoke eval();



=========================================================
while (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top