Javascript: convert string to object

i have 10 fields a1 to a10…i want to loop to all fields and update the values of all fields…

in my loop below i’d like to convert my var “x” as object name “a1”

form = this.document.forms[0];

for (i=1,;i<10;i++)

{

x = “a” + i.toString();

form.x.value = “new value”

//previous line will result into error

//coz “x” is still in string data type…

}

Subject: Javascript: convert string to object

Mabe this. . .

for (i=1;i<10;i++)

{

document.getElementById(“a”+i.toString()).value = “new value”

}

Subject: Javascript: convert string to object

Hi,

you need to use the eval() method, to get a handle to the field with the title of ‘x.’ Just search google for how to use this method, it’s really simple.