[_] Javascript annoyance
Raymond Brooks
ray at conscious.co.uk
Tue Jul 25 15:24:57 BST 2006
Oliver Humpage wrote:
> There must be a quick solution to this:
>
> I want to associate screen names with numbers:
>
> var screenArray = {'topfoyer371':100,'topfoyer372':314};
> // There are more than 2, just included 2 for brevity.
>
> Then when the mapclick() function is called:
>
> mapclick('topfoyer372');
>
> It should do something with the number:
>
> function mapclick(divID) {
> // give debugging information:
> alert(divID+", "+screenArray.topfoyer372+", "+screenArray.divID);
> }
>
>
> This gives an alert saying:
>
> topfoyer372, 314, undefined
>
> Why is screenArray.divID undefined, when screenArray.topfoyer372 *is*
> defined? Do I need to do something to the divID variable to make it work
> when used as an object's property?
>
> Thanks all,
>
> Oliver.
>
>
because it's looking for the literal "screenArray.divID" and there's no
such element. You need to dereference.
Rayx
> There must be a quick solution to this:
>
> I want to associate screen names with numbers:
>
> var screenArray = {'topfoyer371':100,'topfoyer372':314};
> // There are more than 2, just included 2 for brevity.
>
> Then when the mapclick() function is called:
>
> mapclick('topfoyer372');
>
> It should do something with the number:
>
> function mapclick(divID) {
> // give debugging information:
> alert(divID+", "+screenArray.topfoyer372+", "+screenArray.divID);
> }
>
>
> This gives an alert saying:
>
> topfoyer372, 314, undefined
>
> Why is screenArray.divID undefined, when screenArray.topfoyer372 *is*
> defined? Do I need to do something to the divID variable to make it work
> when used as an object's property?
>
> Thanks all,
>
> Oliver.
>
>
because it's looking for the literal "screenArray.divID" and there's no
such element. You need to dereference.
Rayx