Jump to content

Archived

This topic is now archived and is closed to further replies.

leon

javascript in php code

Recommended Posts

Hello, I was trying to insert rollover image script to php. But I dont think it will be easy. can you check this code please? How can it be adjusted?


[code]
<?php echo "<a href=\"$PHP_SELF?page=$pageNum&product_id={$data['id']}\" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image71','','{data['image_roll']}',1)">"; ?>
[/code]

Image_roll is the field from the database.

Share this post


Link to post
Share on other sites
Javascript is all run after your PHP is parsed, so basically just get PHP to echo exactly what you want to appear in the browser.

As long as your slashes and brackets dont overlap (for want of a better word appearing in my head right now) it will work fine.

Share this post


Link to post
Share on other sites
you might be forgetting to escape your quotes. When using quotes within quotes, you need to put a backslash infront of the internal quote...

so, "\"" would equal "

I added backslashes to your code around the mouseover and mouseout -- should work fine now.


[code]
<?php echo "<a href=\"$PHP_SELF?page=$pageNum&product_id={$data['id']}\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image71','','{data['image_roll']}',1)\">"; ?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.