how to toggle images when one clicks a image/ link

  • Thread starter Madame Blablavatsky
  • Start date
M

Madame Blablavatsky

hello,

i have an image that is also a link:

<a href="javascript:eek:pmaak('bold','')"><img src='bold_uit.gif
name='uit'></a>

when the image/link is clicked it triggers a javascript that enables people
to type bold.

when people click the link i want the image to change.
and when they click the link again to stop the text beeing bold, i want the
image to change again to
the original image.

the effect is the same as in a wordprocessor when you want to type bold.
the image shows if the function is on or of.

does anyone know how to do this?

thanks
 
T

tom

Hello,

this is pretty easy to do, you need to include some lines in your
opmaak function, something like this:

if (document.uit.src=='image1.jpg')
document.uit.src = image2.jpg;
else
document.uit.src = image1.jpg;

regards,
Tom
 
E

Evertjan.

tom wrote on 05 sep 2005 in comp.lang.javascript:
Madame Blablavatsky wrote on 05 sep 2005 in comp.lang.javascript:

[please quot in a way that others do'n't have to search for older
postingd.
this is pretty easy to do, you need to include some lines in your
opmaak function, something like this:

if (document.uit.src=='image1.jpg')
document.uit.src = image2.jpg;
else
document.uit.src = image1.jpg;

Better use 'this' to be multi browser compliant,
and there is not much sense in using a hyperlink,
just do a img onclick:

<img src='bold_uit.gif' onclick = 'swapBold(this)'>

<script type = 'text/javascript'>
var bold = false; // to use in the bold-allowing script

function swapBold(x){
x.src = (x.src== 'bold_uit.gif')?'bold_aan.gif':'bold_uit.gif'
bold = (x.src == 'bold_aan.gif')
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top