Dear All,
In short, this works:
function testEval(){
var veh = "car";
eval(veh + "Ford" + "models" + "= new
Array('Fiesta', 'Mondeo','Falco n');");
for(i = 0; i < 3; i++){
alert("The model: " + carFordmodels[i]);
}
}
This doesn't:
function testEval(){
var FordModels = new Array('Fiesta', 'Mondeo','Falco n');
var veh = "car";
eval(veh + "Ford" + "models" + "=" + FordModels);
for(i = 0; i < 3; i++){
alert("The model: " + carFordmodels[i]);
}
}
The browser (two of them) thinks Fiesta is an undefined variable. How
do I get the second example to work, i.e. where there is a reference to
an Array of Strings. I also tried eval(veh + "Ford" + "models") =
FordModels; but no luck.
I'm quite stuck.
Thanks in advance.
Chris
In short, this works:
function testEval(){
var veh = "car";
eval(veh + "Ford" + "models" + "= new
Array('Fiesta', 'Mondeo','Falco n');");
for(i = 0; i < 3; i++){
alert("The model: " + carFordmodels[i]);
}
}
This doesn't:
function testEval(){
var FordModels = new Array('Fiesta', 'Mondeo','Falco n');
var veh = "car";
eval(veh + "Ford" + "models" + "=" + FordModels);
for(i = 0; i < 3; i++){
alert("The model: " + carFordmodels[i]);
}
}
The browser (two of them) thinks Fiesta is an undefined variable. How
do I get the second example to work, i.e. where there is a reference to
an Array of Strings. I also tried eval(veh + "Ford" + "models") =
FordModels; but no luck.
I'm quite stuck.
Thanks in advance.
Chris
Comment