Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick to change image

Status
Not open for further replies.

rachelason

Programmer
Jun 28, 2004
114
GB
HI! can someone help me here.
I am trying to change the image on clicking the image. It's a button which changes colour basically but the two colors are stored as an image.
this is the code

<td align="center">
<a href="viewhouseplan.html" target="edit"
onMouseover="document.vie.src='iconviewhouse2.gif'"
onMouseout="document.vie.src='iconviewhouse.gif'">
<img src="iconviewhouse.gif" name="vie" width="135" height="14" border="0"></a>
</td>

It's a list of menu which displays iconviewhouse.gif in the first place. on placing the mouse over, it displays iconviewhouse2.gif and onmouseout it goes back to the original picture. What i want to do is once the image is clicked it should stay in iconviewhouse2.gif. I tried to write a function i.e.,

function changingImage(imag2,nam){
document.nam.src=imag2;} and called this in href onclick, but it doesn't do a thing. can someone helpme. Thanks in advance.
 
Try:

function changingImage(imag2,nam)
{
document.images[nam].src=imag2;
}
 
thanks for your reply, but it doesn't work, this is the code i have added in in the href

onclick="javascript:changingImage('iconviewhouse2.gif','vie')"
Can't see why it doesn't work. Any other suggestion?
 
thanks for your reply, it seem to change the picture but doesn't stay like that. Obviously i need to have something done in the <img src> tag i guess. Any suggestion ?is there a way i can set the image as a variable and assign it to the src rather than calling the actual image itself.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top