...

View Full Version : Newbie Question



ole90
06-18-2008, 05:12 PM
Hey guys,
I'm very new to JavaScript programming and so I wrote this function today to try and change the image with a simple click of a button. Code:


<html>
<head>
<title>Testing Javascript</title>
<script language="JavaScript" type="text/javascript">
<!--

function changeimage() {
var img = document.getElementById("Myimage");
img.src="newimage.png";
}
// -->
</script>
</head>
<body>
<img src="myimage.png" name="Myimage" ID="Myimage">

<form name="changeimage">
<input type="button" value="Change Image" onClick="changeimage();">
</form>
</body>
</html>

But for some reason this does nothing :X Could someone explain what is wrong :X? Thanks!

Forever Zero
06-18-2008, 05:47 PM
This isn't exactly what you're trying to do, but maybe this will help you out?

http://www.javascript-coder.com/button/javascript-button-p1.phtml

abduraooft
06-18-2008, 06:14 PM
<form name="changeimage">
<input type="button" value="Change Image" onClick="changeimage();">
</form>
Use two different names for your form and function

PS: A form is not actually required to use a button



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum