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

Alternate images not working

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
Hi everyone,
This is my first javascript code and it is not working for me !
I try to place an image at a div. What that image would be it depends on a parameter I send to a js function.
This is what my HTML page:
Code:
<!DOCTYPE html>
<!--to-forum.html-->
<html lang = "he">
<head>
	<title>js</title>
	<meta charset="utf-8" />
	
	<script>
		function ChangeImage(xx)
		{ 
			if(xx=='1')
			{
				return("../images/greensilver.gif");
			}
			if(xx=='2')
			{
				return("../images/greensilver1.gif");
			}
		}
	</script>
</head>

<body>
	<div id="logo"> 
		<img id="myImg" src="ChangeImage('1')" />
	</div>
</body>
</html>
When I run it, the picture doesn't show up. Nothing shows up :-(.
Could anyone instruct me how to do it right ?
Thanks
 
You do not tell it to 'change', 'src' is NOT an event attribute so does not trigger a function.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top