Re: toggle image

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: pvp urologist Dallas
    ... A Google search of your urologist found this website: ... Dave ... Prev by Date: ...
    (sci.med.prostate.bph)
  • Re: PCBs with edge connectors?
    ... Does Hans Franke have a website? ... Dave ... Prev by Date: ...
    (comp.sys.apple2)
  • toggle image
    ... I want to toggle an image based on a button click. ... Dave ... Prev by Date: ...
    (microsoft.public.scripting.jscript)
  • old wood bars
    ... I see the website is no more. ... Does anyone know where I could purchase ... Prev by Date: ...
    (rec.crafts.brewing)
  • Re: toggle image
    ... > Dave wrote: ... >> I want to toggle an image based on a button click. ... > function img2() ... Prev by Date: ...
    (microsoft.public.scripting.jscript)