0

I am selecting two image from database and want to show them onMOuseOver and onMouseOut.

Here is my code:

<img onmouseover="this.src=' .$him[0]. '" onmouseout="this.src='.$image_full[0].'" src="'.$image_full[0].'"  />
Jaap
  • 81,064
  • 34
  • 182
  • 193
Shamsur Rahman
  • 283
  • 5
  • 19

2 Answers2

1

I'm not sure if you like php print html code or html print php code, in both cases, be carefull with ' and ":

PHP print html code:

echo '<img onmouseover="this.src=\'' .$him[0]. '\'" onmouseout="this.src=\''.$image_full[0].'\'" src="'.$image_full[0].'"  />';

HTML print PHP code:

<img onmouseover="this.src='<?php echo $him[0] ?>'" onmouseout="this.src='<?php echo $image_full[0] ?>'" src="'<?php echo $image_full[0] ?>'"  />

If you try html print php code, you need to save your html code as php code

Aimeé RP
  • 114
  • 1
0

Could be the single quotatation marks in the 'src' property. Seems like they shouldn't be there, only for the javascript events because there's a string inside a string.

Without the extra single quotation marks it seems to work just fine for me.

Example:

<img
  onmouseover="this.src='https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/AndalusQuran.JPG/94px-AndalusQuran.JPG'"
  onmouseout="this.src='https://upload.wikimedia.org/wikipedia/commons/thumb/c/cc/Nacreous_clouds_Antarctica.jpg/110px-Nacreous_clouds_Antarctica.jpg'"
  src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/140626_Tierser_Alpl_Rossz%C3%A4hne.jpg/245px-140626_Tierser_Alpl_Rossz%C3%A4hne.jpg"
/>
Richard
  • 390
  • 3
  • 10