1 Replies - 509 Views - Last Post: 13 October 2008 - 03:27 PM

#1 inc0mplete  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 45
  • Joined: 10-May 08

help changing image.

Post icon  Posted 13 October 2008 - 10:17 AM

Hi! I am trying to change the image, but it doesn't seem to work. I don't know why. Here is my code, any help would be great. Thanks!
<html>
<head>
	<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
	<title>velo2</title>
	<link rel="stylesheet" href="velo.css" type="text/css">
	<script type="text/javascript">
		function change(img_name){
			var update_name = "velo/"+img_name;
			document.image.src=update_name;
		}
	</script>
</head>

<body>
	<script type="text/javascript">
	var test="velo/" + "headerimg_2.jpg";
	</script>
<div class="container">
<div class="menu">
<ul>
<li><a href="velo2.html" class="about"></a></li>
<li><a href="#" id="menu2" class="menu2" onclick="change(headerimg2_jpg)" ></a></li>
<li><a href="#" id="wine" class="wine"></a></li>
<li><a href="#" id="events" class="events"></a></li>
<li><a href="#" id="press" class="press"></a></li>
<li><a href="#" id="contact" class="contact"></a></li>
<li><a href="#" id="directions" class="directions"></a></li>
</ul>
</div>



Is This A Good Question/Topic? 0
  • +

Replies To: help changing image.

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1167
  • View blog
  • Posts: 7,207
  • Joined: 07-September 06

Re: help changing image.

Posted 13 October 2008 - 03:27 PM

Well, in the code you provided you don't actually have an image anywhere, which is probably the reason you don't see any update when you call the function.

Additionally hyou have the issue that you are sending the parameters to the function as if it was a variable name, not a string. Then you are calling document.image, but that doesn't mean anythin either.

Try something more like so:

<html>
<head>
	<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
	<title>velo2</title>
	<link rel="stylesheet" href="velo.css" type="text/css">
	<script type="text/javascript">
		function change(id, newSrc){
			obj = document.getElementById(id);
			var update_name = "velo/"+newSrc;
			obj.src = update_name;
		}
	</script>
</head>

<body>
	<script type="text/javascript">
	var test="velo/" + "headerimg_2.jpg"; // THIS CODE DOES NOTHING
	</script>
<div class="container">
<img id="TEST_ID" src="" />
<div class="menu">
<ul>
<li><a href="velo2.html" class="about"></a></li>
<li><a href="#" id="menu2" class="menu2" onclick="change('headerimg2_jpg', 'TEST_ID')" ></a></li>
<li><a href="#" id="wine" class="wine"></a></li>
<li><a href="#" id="events" class="events"></a></li>
<li><a href="#" id="press" class="press"></a></li>
<li><a href="#" id="contact" class="contact"></a></li>
<li><a href="#" id="directions" class="directions"></a></li>
</ul>
</div>



HTH
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1