View Full Version : :: looking for an image toggle script.. ::

10-17-2003, 10:33 AM
i want a script that when user clicks on a text link the image beside it toggles between 2 images

its basically for a tree menu system i got but for some reason everything i do refuses to work..

here is what i have...


<table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td width="10" valign="top">

<img src="http://www.simonsgroup.com/kamtoolbox/images/plusImage.gif" border="0" align="absmiddle" name="A4279028BD175F3380256DBB005182C7">

</td><td class="mainsection" onMouseOut="tableOut(this)" onMouseOver="tableOver(this)">

<a class="expandable" href="javascript:;" onClick="this.blur()"> Consultant contact</a><br>

<p class="subsection" style="display:none">
<img src="http://www.simonsgroup.com/kamtoolbox/images/linkImage.gif" border="0" align="absmiddle"><a href="http://www.simonsintranet.com" target="_blank"> How to contact </a><br>
<img src="http://www.simonsgroup.com/kamtoolbox/images/docImage.gif" border="0" align="absmiddle"><a href="B5E9593546F2BE4C80256DBF003CF04E/$file/contract.pdf" target="_blank"> What to do after contact</a><br>


the bold bit is the link and the italic is the image that needs to be swapped

image locations are:


thx all

i thought i could do a simple if image = minus swap to plus and if plus swap to minus but for some reason i cant get it working ...

help plz its doing my head in :(

10-17-2003, 10:59 AM
var plus = new Image();
plus.src = "images/plusImage.gif";
var minus = new Image();
minus.src = "images/minusImage.gif";

function toggle(objLink, imgName){
document.images[imgName].src = (document.images[imgName].src==plus.src) ? minus.src:plus.src;
return false; //cancel action of href


<img src="http://www.simonsgroup.com/kamtoolbox/images/plusImage.gif" border="0" align="absmiddle" name="A4279028BD175F3380256DBB005182C7">
<a class="expandable" href="#" onclick="return toggle(this,'A4279028BD175F3380256DBB005182C7')">Consultant contact</a><br>

10-17-2003, 11:28 AM
:thumbsup: :thumbsup: :thumbsup:

spent ages tyrying this last night - im assuming that it was more the lack of knowledge than logic as my logic seemed ok...

thanks a million :)