try using the eval function _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
<html>
<head>
<script>
var heading = "Option one arrays";
var myArray = new Array();
for(var i=0;i<=24;i++){ //loop through to 24
myArray = "value " + i; //give avlue to array
eval('var var'+i+'=myArray'); //create variable with array value
alert(eval('var'+i)); //test
document.write("value "+myArray+" created<br>"
}
</script>
</html>
two things here. first I would use arrays but if that is something you do not want to do with in the loop I show the variable creation. _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
a bit more explanation while running through the code
var mag = "";
var myArray = new Array();
for(var i=0;i<=24;i++){
myArray = "value " + i;
eval('var var'+i+'=myArray');
msg = "var"+i+" variable create with value "+ eval('var'+i);
alert(msg);
document.write("value "+myArray+" created<br>"
} _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
sorry,
var mag = "";
var myArray = new Array();
for(var i=0;i<=24;i++){
myArray = "value " + i;
eval('var var'+i+'=myArray');
msg = "var"+i+" variable create with value "+ eval('var'+i);
alert(msg);
document.write("value "+myArray+" created<br>"
} _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
alright I quite for the day. this cold is clouding my brain
change that mag declaration to msg. even knowing that doesn't really matter. _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
this line eval('var var'+i+'=myArray');
dynamically creates a variable with the value of the array element currently selected
I think that is what they wanted. although seemingly long winded when you can use arrays _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
ok forget the i's and try it again with x's.
this line eval('var var'+x+'=myArray[x]');
dynamically creates a variable with the value of the array element currently selected
_________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
that creates a value of the array element not a variable _________________________________________________________
for the best results to your questions: FAQ333-2924 01001111 01101110 01110000 01101110 01110100
if document.write(myArray[7]); outputs "value7" how is that not creating a variable? myArray[7] is a variable (of an array) holding the value of "value7" ???
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.