[Javascript] dynamic variables names

Geoff Corriere geoff at cpe1.com
Tue Jun 24 14:03:10 CDT 2003


This is close:

> I have tried using alert(document.images); and it did trace to 
> [object] which is correct, but when I try to do 
> alert(document.images[nt_01]) or alert(document.images[nt_01].src) all 
> I get is an undefined and I don't know why.
>

document.images[nt_01] does reference a specific object, but you cannot 
alert() an object. You can alert an attribute of an object. 
alert(document.images['nt_01'].name) would get you what you want. Also, 
note the ' ' used. images['img_name'] is an associative array, so you  
need quotes. The example I sent you placed the name of the image in a 
variable first:

var next_image = "nt_01";
alert(document.images[next_image].name);

No quotes are needed in that example.


Geoff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 783 bytes
Desc: not available
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030624/31c231a4/attachment.bin>


More information about the Javascript mailing list