Link to home
Start Free TrialLog in
Avatar of rwhubbard996
rwhubbard996Flag for United States of America

asked on

Hoover Buttons & PHP

I am trying to get hover, or rollover buttons to work.  I want to swap between two images when the mouse goes over the button.  I have no trouble in HTML but cant get it to work when I put it in my PHP code.  

The last thing I tried was to enclose the java call between print <<< HERE like so:

print <<<HERE
      <table width="800" border="0" align="center" cellpadding="0">
<tr><td align="center"><a href="#tp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('back-to-top','','buttons/back_top.jpg',1)"><img src="buttons/back_top_on.jpg" name="back-to-top" width="101" height="27" border="0"></a></p>
</td></tr></table>
HERE;

I also tried jumping in and out of PHP and printing them in the code by print '...   ....';

Here is the java code generated by DreamWeaver:

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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

function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

Thanks
Avatar of alextr2003fr
alextr2003fr

when you include your java code and it have ' in it use \' to escape
for example in your case :
$html = '
 <table width="800" border="0" align="center" cellpadding="0">
<tr><td align="center"><a href="#tp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'back-to-top\',\'\',\'buttons/back_top.jpg\',1)"><img src="buttons/back_top_on.jpg" name="back-to-top" width="101" height="27" border="0"></a></p>
</td></tr></table>';

and if you use something like $html = " ... some code... ";  in it then you should escape all internal " with \"
PS : then to output it you can use print($html); or echo $html;
Avatar of rwhubbard996

ASKER

I did that    echo $html;  but it still is't working.  When the page was loading I thought it worked?  Maybe I imagined it?

Any other ideas?
did you try to see what does the source code of the page says is the code actually printed inside?
also if you get any php errors, can you copy/paste them here.
This is from the generated HTML code:

<table width="800" border="0" align="center" cellpadding="0">
<tr><td align="center"><a href="#tp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('back-to-top','','buttons/back_top.jpg',1)"><img src="buttons/back_top_on.jpg" name="back-to-top" width="101" height="27" border="0"></a>
</td></tr></table>

No PHP error codes.
then maybe it is your html code?
That looks right to me, but still not working.
I'll test that.
try to paste your raw html in another page and see if it works (outside Dreamwaver)
what if the java call is inside a  PHP function?  I made $html global  maybe I'm still trapping a varriable in the function?

I put another button in the html code above most of the PHP and it worked.
The button appears, the link to the anchor works, it just won't swap images.
try to check the paths to the images
are you sure it will swap to something since that command seems to me calling same image?
MM_swapImage('back-to-top','','buttons/back_top.jpg',1)"><img src="buttons/back_top_on.jpg"
when you roll over on it shows the same back_top.jpg in both cases no?
maybe it should be another image as replacement
I'll check,  That would fall under user error ;-0
not that,  one image back_top_on.jpg  the other image is  back_top.jpg  notice the "_on" on one image.
ok i see but seems like a html/java problem now, or just code place problem
I put the same code earily and it worked.  Then I copied itside in the function and not only did that not work the working vesion quit working.  ?
ASKER CERTIFIED SOLUTION
Avatar of alextr2003fr
alextr2003fr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial