Konrad Mathieu wrote on 05 jul 2003 in comp.lang.javas cript:[color=blue]
> How do I - within in a function - make Javascript recognize a string as a
> variable name?[/color]
<script>
var a="blah"
var blah="bloob"
var blib="bloobbloo b"
function f(){
alert(window[a])
alert(window["blib"])
}
f() // alerts: bloob, bloobbloob
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
In article <1057428393.522 24.0@iris.uk.cl ara.net>, "Konrad Mathieu"
<nospam@nospam. com> writes:
[color=blue]
>How do I - within in a function - make Javascript recognize a string as a
>variable name?
>
>Thanks and cheers,
>Konrad[/color]
How you do that depends on what the string's variable representation
represents.
For the most part, you simply use bracket notation.
If the string points at a variable, window['StringHere'] will give you a
reference to global variables (there are some cavaets to it I believe).
If its a name of a form element:
document.forms[varName].elements[varName2].propertyName
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
"HikksNotAtHome " <hikksnotathome @aol.com> schrieb im Newsbeitrag
news:2003070514 4428.08200.0000 0613@mb-m25.aol.com...[color=blue]
> In article <1057428393.522 24.0@iris.uk.cl ara.net>, "Konrad Mathieu"
> <nospam@nospam. com> writes:
>[color=green]
> >How do I - within in a function - make Javascript recognize a string as a
> >variable name?
> >
> >Thanks and cheers,
> >Konrad[/color]
>
> How you do that depends on what the string's variable representation
> represents.
>
> For the most part, you simply use bracket notation.
>
> If the string points at a variable, window['StringHere'] will give you a
> reference to global variables (there are some cavaets to it I believe).
>
> If its a name of a form element:
>
> document.forms[varName].elements[varName2].propertyName
> --
> Randy
> All code posted is dependent upon the viewing browser
> supporting the methods called, and Javascript being enabled.[/color]
Comment