-1

I'm having trouble creating the mouseover and mouseout states of the image because I have a quote inside a quote inside a quote. Is when I use the PHP code below I receive an Uncaught SyntaxError because the " before $id is closing the entire line. Any ideas how to get around this? Thanks!

<img src="inventory_images/' . $id . '_1medium.jpg" onmouseover="this.src=\'inventory_images/\" . $id . \"_2medium.jpg\';" onmouseout ="this.src=inventory_images/" . $id . "_1medium.jpg;" />
vtj205
  • 265
  • 1
  • 5
  • 18

2 Answers2

0

Look into String Interpolation over Concatenation when using simple data. All you have to do is surround the variable in {} curly braces. You also left off a ;.

<img src="inventory_images/{$id}_1medium.jpg" 
    onmouseover="this.src='inventory_images\{$id}\_2medium.jpg';" 
    onmouseout ="this.src='inventory_images\{$id}\_1medium.jpg';" />

The path may not be correct I assumed inventory_images\id\image you can just remove the \ between id and underscore if needed with out modifying anything else.

nerdlyist
  • 2,842
  • 2
  • 20
  • 32
0

I figured it out. In case anyone else has this same issue here was my fix.

<img src="inventory_images/' . $id . '_1medium.jpg" onmouseover="this.src=\'inventory_images/' . $id . '_2medium.jpg\';" onmouseout ="this.src=\'inventory_images/' . $id . '_1medium.jpg\';"/>
vtj205
  • 265
  • 1
  • 5
  • 18