purcaholic said the following on 6/9/2007 4:15 AM:
On 9 Jun., 08:26, Tuxedo <tux...@mailinator.netwrote:
>How can I modify any one of these global variable identified via a function
argument?
var x1 = "bla";
var x2 = "bla";
var x3 = "bla";
function modify(variable) {
???? [variable]???? = "blabla":
}
The following onclick should change the string value of variable 'x1' from
"bla" to "blabla", via the above modify() function.
<a ... onclick="modify('x1')">
Thanks in advance for any aswer to this simple question.
You can use eval() to evaluate a string like eval(variable + ' =
"blabla";'); inside modify() method.
You can use a sledgehammer to drive a tack in the wall also. Does that
mean you do it though?
window[variable] = "blabla";
alert('Look Ma, no eval and no if/else switch crap!!!')
Better is usage of an a switch if/else if, scanning passed parameter
and setting corresponding global variable or usage of an global
assoziative array and passing the array key to the function.
Can you explain how to create an "associative array" in javascript?
Beware, it is a loaded question.
Besides, why do all that trouble when it is quite simple? See above.
P.S. It has been a bad night so excuse my tone, I am just too tired to
give a crap right now.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/