Click to See Complete Forum and Search --> : javascript question - evaluate a string


inaam
April 29th, 2003, 02:28 AM
I'm a beginner in coding javascript.
I am building a string where sboxname carries the select box name, the alert message displays the string correctly then I want to extract the value of the selected index and compare it within the If statement.

Any ideas how to do it, please?

sindex="document.form2."+sboxname+".selectedIndex";
alert("selected index string: "+sindex);
if(sindex==1)

Satishpp
April 29th, 2003, 03:41 PM
Change this line

sindex="document.form2."+sboxname+".selectedIndex";


to


sindex = eval("document.form2."+sboxname+".selectedIndex");

The eval function will do your job.

Satish

inaam
April 30th, 2003, 03:21 AM
Thanks Satishpp for replying back with a solution and it works :)