Re: toggle image
- From: "Trevor L." <tandcl@xxxxxxxxxxxxxxx>
- Date: Tue, 10 Jan 2006 17:44:19 +1100
Dave wrote:
> I want to toggle an image based on a button click.
This code works
( I used some existing images of my own: images/1.jpg and images/2.jpg)
<html>
<head>
<script type="text/javascript">
function img2()
{
alert(document.box.src);
if (document.box.src.indexOf("images/2.jpg") > 0)
{
alert('1');
document.box.src = "images/1.jpg";
}
else
{
alert('2');
document.box.src = "images/2.jpg";
}
};
</script>
</head>
<body>
<p>
<IMG name="box" src=images/1.jpg>
</p>
<p>
<INPUT type="button" value="click" onclick="img2()" >
</p>
<body>
</html>
I tested for the presence of the image name within the string
document.box.src.
So this should work on your local disk (which is where I tested it) or on
the web
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
.
- Follow-Ups:
- Re: toggle image
- From: Evertjan.
- Re: toggle image
- References:
- toggle image
- From: Dave
- toggle image
- Prev by Date: Re: If statement
- Next by Date: Re: toggle image
- Previous by thread: toggle image
- Next by thread: Re: toggle image
- Index(es):
Relevant Pages
|