Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu Image Swap (stay)

Status
Not open for further replies.

NiteCrawlr

Programmer
Mar 16, 2001
140
BR
I have a menu on my site, with images. when the menu is not in use, it uses image 1 (for example), then when I hover the mouse pointer over it, it shows image 2. That is working fine, but how can I make image 2 stay after I click on it.
After I click on it, image 1 comes back....

help... please

here is the code:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function MM_swapImgRestore() { //v2.0
if (document.MM_swapImgData != null)
for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
document.MM_swapImgData.src = document.MM_swapImgData[i+1];
}

function MM_swapImage() { //v2.0
var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
(objStr.indexOf('document.all[') ==0 && document.all ==null))
objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
obj = eval(objStr);
if (obj != null) {
swapArray[j++] = obj;
swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:eek:ldArray[j];
obj.src = MM_swapImage.arguments[i+2];
} }
document.MM_swapImgData = swapArray; //used for restore
}

//-->
</SCRIPT>


Thank you

Frederico
 
NiteCrawlr,

I presume that you are using the onMouseOver to change the image when you hover over it. Just use the same code with the onClick event to keep the &quot;hover&quot; image. Mise Le Meas,

Mighty :)
 
<TR>
<TD ALIGN=&quot;LEFT&quot;><A HREF=&quot;produtos.htm&quot; TARGET=&quot;corpo&quot;
ONMOUSEOVER=&quot;MM_swapImage('document.menu_prod','document.menu_prod','imagens/menu_prod2.gif','#961448264207')&quot;
ONMOUSEOUT=&quot;MM_swapImgRestore()&quot;><IMG SRC=&quot;imagens/menu_prod.gif&quot; WIDTH=&quot;115&quot;
HEIGHT=&quot;27&quot; NAME=&quot;menu_prod&quot; BORDER=&quot;0&quot;></A></TD>
</TR>


This is how I am calling the functions......

Thanks
 
If you want the image to stay the same then try adding the onClick event and try something like the following:

&quot;><A HREF=&quot;produtos.htm&quot; TARGET=&quot;corpo&quot;
ONMOUSEOVER=&quot;MM_swapImage('document.menu_prod','document.menu_prod','imagens/menu_prod2.gif','#961448264207')&quot; ONCLICK=&quot;MM_swapImage('document.menu_prod','document.menu_prod','imagens/menu_prod2.gif','#961448264207')&quot;
ONMOUSEOUT=&quot;MM_swapImgRestore()&quot;><IMG SRC=&quot;imagens/menu_prod.gif&quot; WIDTH=&quot;115&quot;
HEIGHT=&quot;27&quot; NAME=&quot;menu_prod&quot; BORDER=&quot;0&quot;></A>

See if that works. Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top