Jump to content


Javascript Problem


2 replies to this topic

#1 _*Creative Insanity_*

  • Guests

Posted 24 March 2007 - 04:35 PM

Ok.. hi all.
I have got a script off the web (from tutorial) and it works a treat and here it is:
<a href="java script:;" onmouseover="toggleDiv('mydiv');" onmouseout="toggleDiv('mydiv');">Toggle Div Visibility</a>
and the js is:
 function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
	  document.getElementById(divid).style.display = 'block';
	}else{
	  document.getElementById(divid).style.display = 'none';
	}
  }

Now what I am trying to get to work is the hidden divs AS well as the mouse over for the link images.. but what ever I try fails. I thought that this below would work but nup.. my js is not flash hot at all, actually real bunny.


So I added that js to my mouse over script file and get this:
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
 function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
	  document.getElementById(divid).style.display = 'block';
	}else{
	  document.getElementById(divid).style.display = 'none';
	}
  }
and my new link line is this:
<a href="inc/products.php?cat=prod" onmouseout="swapImgRestore(),'toggleDiv('mydiv')'" onmouseover="swapImage('link2','toggleDiv('mydiv')','image/link2_on.png',2)" alt="Products Page"><img src="image/link2.png" name="link2" width="35" height="39" border="0" id="link2" /></a>
and my hidden div is this, which worked with the original posted above.
<div id="mydiv" style="display:none">Products Page</div>

So please some one, tell me what this old bugger is doing wrong?

Ta muchly

#2 _*Creative Insanity_*

  • Guests

Posted 24 March 2007 - 04:46 PM

Thanks Adam, will do so now.. I got the mouse out to work, but not mouse over with this:
<a href="inc/products.php?cat=prod" onmouseout="swapImgRestore(),toggleDiv('mydiv')" onmouseover="swapImage('link2','','image/link2_on.png',2),toggleDiv('mydiv')" alt="Products Page"><img src="image/link2.png" name="link2" width="35" height="39" border="0" id="link2" /></a>
Will try your line now.

YES! worked a treat.. thanks so much Adam.. so from my line above only needed to move the toggle command and over would of work.. great.. thanks heaps!

Edited by Creative Insanity, 24 March 2007 - 04:53 PM.


#3 _*Creative Insanity_*

  • Guests

Posted 24 March 2007 - 06:19 PM

Will keep that in mind next time. ;)
Will display the site once I have something on line so you can see what I was doing.. looks nice also.

Thanks again.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users