• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

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
0
rwhubbard996
Asked:
rwhubbard996
  • 10
  • 9
1 Solution
 
alextr2003frCommented:
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 \"
0
 
alextr2003frCommented:
PS : then to output it you can use print($html); or echo $html;
0
 
rwhubbard996Author Commented:
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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
alextr2003frCommented:
did you try to see what does the source code of the page says is the code actually printed inside?
0
 
alextr2003frCommented:
also if you get any php errors, can you copy/paste them here.
0
 
rwhubbard996Author Commented:
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.
0
 
alextr2003frCommented:
then maybe it is your html code?
0
 
rwhubbard996Author Commented:
That looks right to me, but still not working.
0
 
rwhubbard996Author Commented:
I'll test that.
0
 
alextr2003frCommented:
try to paste your raw html in another page and see if it works (outside Dreamwaver)
0
 
rwhubbard996Author Commented:
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.
0
 
rwhubbard996Author Commented:
The button appears, the link to the anchor works, it just won't swap images.
0
 
alextr2003frCommented:
try to check the paths to the images
0
 
alextr2003frCommented:
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
0
 
rwhubbard996Author Commented:
I'll check,  That would fall under user error ;-0
0
 
rwhubbard996Author Commented:
not that,  one image back_top_on.jpg  the other image is  back_top.jpg  notice the "_on" on one image.
0
 
alextr2003frCommented:
ok i see but seems like a html/java problem now, or just code place problem
0
 
rwhubbard996Author Commented:
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.  ?
0
 
alextr2003frCommented:
that is strange, try to use the working version and follow the rule by escaping all ' in your java code with \'
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now