JavaScript variable variable?
Posted: Sat Jun 14, 2008 11:15 am
I have a script that dynamically creates a variable called the_var_import. When I echo the_var_import it gives me the name of the variable I want to compare another variable to. After recently learning how to do variable variables in PHP I am trying to figure out how to turn the_var_import in to a variable variable. So it's string (in example 'ii00') would become the variable I compare the other variable to.
So I want to turn this comparison...
...in to this comparison...
...by turning the_var_import in to a variable variable.
Here is the script...
So I want to turn this comparison...
Code: Select all
if (ce00 == the_var_import)Code: Select all
if (ce00 == ii00)Here is the script...
Code: Select all
function fill_values(my_param){ for (var i=0; i<3; i++) //26 { var the_selector = i; var the_var_form = 'ce' + the_selector + '0'; var the_var_import = 'ii' + my_param + '0'; alert(the_var_form + ' ==?== ' + the_var_import); if (document.getElementById(the_var_form).value == the_var_import) {alert(the_var_form + 'match at ii' + the_selector + '0');} else {alert(document.getElementById(the_var_form).value + '\n\n' + the_var_import);} }} function fill_values_exec(){ for (var i=0; i<3; i++) //26 { fill_values(i); }}