tags:

views:

90

answers:

1

Hi All,

Please help me with this question I am trying to change the source of an image dynamically.

+4  A: 

Client-side (Dynamic) Image-Swapping...

You'll need to use javascript for this:

<img src="image1.jpg" id="myImage" />

<script type="text/javascript">
  document.getElementById("myImage").src = "image2.jpg";
</script>

Introducing jQuery...

If this is the type of response you are looking for, then I would also like to extend an invitation to you to start checking out and javascript framework like jQuery, which makes this type of stuff much easier to do/manage. In jQuery, you can accomplish the same thing with the following code:

$("#myImage").attr("src", "image2.jpg");
Jonathan Sampson
Or any server side language: src="[% myimage %]". Depending on what "dynamic" means in context.
David Dorward
Correct. With the context of "html," I thought it was safe to assume he was speaking of client-side "dynamic," but the question is indeed equivocal.
Jonathan Sampson