Search code examples
javascriptphponmouseoveronmouseout

onmouseover and onmouseout


i have a problem with onmouseover and onnmouseout, it doesn't work.

$tr_mouseover = "#d3d3d3";
$tr_mouseout = "#bababa";

$table_height = "<tr bgcolor=".$tr_bg." height=\"40\" onmouseover=\"this.bgColor=".$tr_mouseover."\" onmouseout=\"this.bgColor=".$tr_mouseout."\"> "; 

Solution

  • Have you tried quoting your color values? Like this:

    $table_height = "<tr bgcolor=".$tr_bg." height=\"40\" onmouseover=\"this.bgColor='".$tr_mouseover."'\" onmouseout=\"this.bgColor='".$tr_mouseout."'\"> ";
    

    Note the ' characters that have been added around the color values. The markup that gets generated should look roughly like this:

    <tr bgcolor="#FF0000" height="40" onmouseover="this.bgColor='#d3d3d3';" onmouseout="this.bgColor='#bababa';">
    

    ...which behaves correctly for me in Chrome, Firefox, and IE.