Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q730 How can I swap the image in an image form element?

irt.org | Knowledge Base | JavaScript | Image | Q730 [ previous next ]

Q730 How can I swap the image in an image form element?

The element:

<input type="image">

is a funny one, as IIRC it wasn't originally a valid form element in Netscape - even worse when used on the Mac.

It isn't an image therefore it won't appear in the images array. It _should_ appear in the elements array - BUT you CANNOT swap elements only images.

Replace the form element with a bulk standard image:

<A HREF="javascript:document.formname.submit()"><IMG SRC="apicture.gif" WIDTH="100" HEIGHT="100" BORDER="0"></A>

and then use normal image swapping JavaScript code to swap the image.

The following was submitted by Harald Paulsen

Use getElementById to find the element in question:

<HTML><HEAD><TITLE>Harald ruller verden</TITLE></HEAD>
<SCRIPT LANGUAGE="javascript">
function nyttbilde() {
  document.getElementById("dings").src = "image2.gif";
}
</SCRIPT>

<BODY onLoad="nyttbilde();">

<FORM>
<INPUT TYPE=image ID=dings SRC="image1.gif">
</FORM>

</BODY>
</HTML>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.