Problem with HTML 4.01 Strict and JavaScript

D

Don G

I am trying to convert my HTML 4.01 Transitional code over to HTML 4.01
Strict (and later into XHTML), but when I go from Transitional to
Strict, part of my JavaScript stops working.

I have validated the HTML, both Transitional and Strict, so I am not
using any deprecated attributes. I have the image coded like this:

<img src="./images/spacer.gif" alt="spacer" name="myImage">

Then I have some JavaScript to change the image depending on the
thumbnail clicked. The JavaScript function is coded like this:

function setImage(imgNum) {
which_image_loaded = imgNum - 1;
if (which_image_loaded < 0)
which_image_loaded = NUMBER_OF_IMAGES - 1;
if (which_image_loaded == NUMBER_OF_IMAGES)
which_image_loaded = 0;
myImage.src = ImageNames[which_image_loaded];
}

Does anyone have a clue as to what the problem might be?

Thank you for your help,

Don
 
M

Mitja

<img src="./images/spacer.gif" alt="spacer" name="myImage">
...
myImage.src = ImageNames[which_image_loaded];
Does anyone have a clue as to what the problem might be?

AFAIK this is a proprietary (IE?) scheme you're using to refer to myImage.
Try
document.getElementById('myImage').src = ImageNames[which_image_loaded];

Mitja
 
D

Don G

AFAIK this is a proprietary (IE?) scheme you're using to refer to
myImage. Try
document.getElementById('myImage').src = ImageNames[which_image_loaded];

Excellent! Thank you very much, that took care of it. This will also
allow me to switch from using the "name" attribute to using the "id"
attribute for images, thus bringing me closer to XHTML! I didn't
realize that what I was doing was proprietary since it worked fine in
Mozilla, but I guess Mozilla is more forgiving in Transitional than in
Strict.

Thanks again,

Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top