Hi guys can anyone help to figure out what's wrong in my code it showing unexpected ','
$list1 .= '<tr onmouseover="this.style.backgroundColor=','#ffff66',';" onmouseout="this.style.backgroundColor=','#d4e3e5',';">
<td>'.$ver.'</td><td>'.$ver2.'</td>
</tr>';
,
is used for passing multiple parameters to echo
, not for concatenating strings to add to be stored in a variable. use .
instead
You can rewrite it like this, escaping the single quotes in the javascript:
$list1 .= '<tr onmouseover="this.style.backgroundColor=\'#ffff66\';" onmouseout="this.style.backgroundColor=\'#d4e3e5\';">
<td>'.$ver.'</td><td>'.$ver2.'</td>
</tr>';
You are not properly concatenating the string/escaping the quotes. You had unnecessary commas. My example also uses double quoted strings so you don't need concatenation
$list1 .= "<tr onmouseover=\"this.style.backgroundColor='#ffff66;'\"
onmouseout=\"this.style.backgroundColor='#d4e3e5'\">
<td>$ver</td><td>$ver2</td></tr>";
To avoid to escape quotes: you can use the heredoc syntax:
$list1 .= <<<EOD
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>$ver</td><td>$ver2</td>
</tr>
EOD;
try this-
$list1 .= "<tr onmouseover='this.style.backgroundColor='#ffff66';' onmouseout='this.style.backgroundColor='#d4e3e5';'><td>".$ver."</td><td>".$ver2."</td></tr>";
working fine for me.