hcl-bot
February 21, 2005, 8:25pm
1
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…
}
hcl-bot
February 22, 2005, 11:06am
2
Subject: Javascript: convert string to object
Mabe this. . .
for (i=1;i<10;i++)
{
document.getElementById(“a”+i.toString()).value = “new value”
}
hcl-bot
February 22, 2005, 5:56am
3
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.