Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] dynamic variables names


  • From: geoff at cpe1.com (Geoff Corriere)
  • Subject: [Javascript] dynamic variables names
  • Date: Tue Jun 24 14:02:57 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.LaTech.edu/pipermail/javascript/attachments/20030624/31c231a4/attachment.bin