Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Image | Q730 [ previous next ]

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>

©2018 Martin Webb