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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change image with onclick

Status
Not open for further replies.

lin73

Programmer
Feb 17, 2006
110
0
0
SE
Hi

I have this javascript that I would like to change images, but it does not work, and since I'm not familiar at all with javascript I could use a little help.

function changeMySrc(i)
{
if i == 1
document.getElementById("Img1").src="Images/folder_open.gif";
document.getElementById("Img2").src="Images/folder.gif";
}
else if i == 2
{
document.getElementById("Img2").src="Images/folder_open.gif";
document.getElementById("Img1").src="Images/folder.gif";
}
}


<a href="#" onclick="changeMySrc(1)" onMouseover="change_img()" onMouseout="change_back()"><img id="Img1" src="Images/folder.gif" /></a>
<a href="#" onclick="changeMySrc(2)" onMouseover="change_img()" onMouseout="change_back()"><img id="Img2" src="Images/folder.gif" /></a><br />

Can someone please tell me what I do wrong?

Regards

 
You're missing some braces and brackets:

Code:
function changeMySrc(i) {
	if [!]([/!]i == 1[!]) {[/!]
		document.getElementById("Img1").src="Images/folder_open.gif";
		document.getElementById("Img2").src="Images/folder.gif";
	} else if [!]([/!]i == 2[!])[/!] {
		document.getElementById("Img2").src="Images/folder_open.gif";
		document.getElementById("Img1").src="Images/folder.gif";
	}
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Worked great, Thanks Dan!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top