By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

how to toggle images when one clicks a image/ link

P: n/a
hello,

i have an image that is also a link:

<a href="javascript:opmaak('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
Sep 5 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Sep 5 '05 #2

P: n/a
tom wrote on 05 sep 2005 in comp.lang.javascript:
Madame Blablavatsky wrote on 05 sep 2005 in comp.lang.javascript:
i have an image that is also a link:

<a href="javascript:opmaak('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

[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>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Sep 5 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.