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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic variable

Status
Not open for further replies.

kjoost001

Programmer
Apr 11, 2002
19
US
wondering if there was anyway to assign a variable dynamically when looping: view code below:

for(nLoopCount = 1; nLoopCount < playerCount; nLoopCount++)
{
var playerStatus = document.write(&quot;form.&quot; + &quot;position&quot; + nLoopCount + &quot;.selectedIndex&quot;);
}

WHAT I'D LIKE TO DO IS ASSIGN PLAYERSTATUS = FORM.POSITION[NUMBER].SELECTEDINDEX EACH TIME THROUGH THE LOOP. MY PROBLEM IS WHEN I ASSIGN IT TO THIS STRING, IT STAYS A STRING.

I want:

form.position1.selectedIndex
form.position2.selectedIndex
...

i want these equal to values, not just &quot;form.position1.selectedIndex&quot;....is there anything like Response.Write like in .ASP?

DO YOU GUYS HAVE ANY IDEAS? thanks.
 
try this:
Code:
[COLOR=blue]
for(nLoopCount = 1; nLoopCount < playerCount; nLoopCount++)
  {
   var playerStatus = document.write(eval(&quot;form.&quot; + &quot;position&quot;   +   nLoopCount + &quot;.selectedIndex&quot;));
}
[/color]
hope it helps! Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
darn lol.. *wants it to be in code tag and blue!!*

Code:
test
Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
this should also work:

document.write(eval(&quot;form.position&quot; + nLoopCount + &quot;.selectedIndex&quot;));

-gnet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top