How to change an image on button click event in javascript ?
A simple and easy example given here. "compman.gif" is my default image and i get the same when i open my application. But i would like give facility to the user to change image on button click event at run time.
This is how we can change an image on button click "document.getElementById("myImage").src="hackanm.gif";" . What is code is doing here is nothing but changing the image url from "compman.gif" to "hackanm.gif".Just try.!
File : ChangeImage_JS.html
<html>
<head>
<script type="text/javascript">
function changeSrc()
{
document.getElementById("myImage").src="hackanm.gif";
}
</script>
</head>
<body>
<img id="myImage" src="compman.gif" width="107" height="98" />
<br /><br />
<input type="button" onclick="changeSrc()" value="Change image">
</body>
</html>
=======================
Publicize yourself ... Free!
http://saalram.com
=======================
Jan 24, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Saalram.com