Lee said the following on 2/25/2007 12:21 AM:
Jammer said:
>Jammer wrote:
>>I want to do something like:
var img_index="dog";
c
images[img_index] is treated like images["img_index"]
I want to use the value of img_index in the images array.
I want to:
document.images[img_index] = "blah";
where img_index = "dog";
so effectively. I want:
document.images["dog"] = "blah";
but then I want:
img_index="cat";
document.images[img_index] = "blah2";
Here is the code I tried:
function openNav( button_name ) {
var img_path = "/images/nav/" + button_name + ".png";
document.images[(button_name)].src = img_path;
The document.images[] array can only be indexed by numbers.
Say again? I have never seen anywhere where the document.images array is
numeric index only. In fact, document.images['imageNAME'] is the most
cross-browser way to access an image object.
document.images["dog"] simply assigns a new attribute to the
images object (in browsers where it's legal to do that).
In what browser does this fail:
<img name="image1" src="myImage1.jpg">
<img name="image2" src="myImage2.jpg">
<img name="image3" src="myImage3.jpg">
<select onchange="alert(document.images[this.value].src)">
<option value="image1">image1
<option value="image2">image2
<option value="image3">image3
</select>
You can do the reverse as well:
<img name="image1" src="myImage1.jpg">
<img name="image2" src="myImage2.jpg">
<img name="image3" src="myImage3.jpg">
<select onchange="document.images[this.value].src='someThingElse')">
<option value="image1">image1
<option value="image2">image2
<option value="image3">image3
</select>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/