img name="" validation question

C

cruiserweight

I am using javascript to switch images. my image tags look like this:

<img src="image.jpg" width="610" height="200" alt="whatever"
name="picture" id="picture" />

obviously, 'name' is not valid with an xhtml strict doc type, but if i
take it out the code breaks in IE. Any thoughts, suggestions? thanks in
advance!
 
J

Jukka K. Korpela

cruiserweight said:
I am using javascript to switch images. my image tags look like this:

<img src="image.jpg" width="610" height="200" alt="whatever"
name="picture" id="picture" />

obviously, 'name' is not valid with an xhtml strict doc type,

Thatäs true.
but if i take it out the code breaks in IE.

It depends on what you do _elsewhere_.

You could upgrade to HTML 4.01 (there's no point in using XHTML on the web
really, except in the context of XML applications perhaps).

Or you could modify your JavaScript code so that it uses other techniques
to access the images, e.g. document.getElementById('picture') (which isn't
supported by very old JavaScript implementations, though).
 
T

Toby Inkster

cruiserweight said:
I am using javascript to switch images. my image tags look like this:
<img src="image.jpg" width="610" height="200" alt="whatever"
name="picture" id="picture" />
obviously, 'name' is not valid with an xhtml strict doc type, but if i
take it out the code breaks in IE.

Take out the name attribute and then fix the Javascript to look at the ID
attribute.
 
N

Neredbojias

With neither quill nor qualm, cruiserweight quothed:
I am using javascript to switch images. my image tags look like this:

<img src="image.jpg" width="610" height="200" alt="whatever"
name="picture" id="picture" />

obviously, 'name' is not valid with an xhtml strict doc type, but if i
take it out the code breaks in IE. Any thoughts, suggestions? thanks in
advance!

Your javascript is probably archaic. How many images are you switching?
There's a fair chance that you don't even need to id (or name) the
images by using document.images[x]...
 
C

cruiserweight

Good idea! This works for both IE and firefox and validates: I dropped
the "name='picture'" bit in the img tag, and changed my javascript code
from this:

function changeImage(img) { document.picture.src = img ; }

to this:

function changeImage(img) { document.getElementById('picture').src =
img ; }

Sweet.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top