Jump to content

mySQL and JavaScript Image Rollovers


princessdeia

Recommended Posts

I want to create an image/text rollover on my site, similar to [url=http://www.deeandjason.co.uk/shop/test.php]this[/url].

All the data is held in a mySQL table. I can get the text part to work, but not the image part.

My code so far is,

javascript function

....
function change(html){
  DESCRIPTION.innerHTML=html
}
....

php code

....
echo "<a href=\"shop.php?c=$cat_id\" onMouseOver=\"change('$cat_description')\" onMouseOut=\"change('DESCRIPTION')\">$cat_name</a><br>";
....

html code
....
<div id="DESCRIPTION">DESCRIPTION</div>
....

Thanks in advance

Dee
Link to comment
https://forums.phpfreaks.com/topic/22356-mysql-and-javascript-image-rollovers/
Share on other sites

This works fine, check that your javascript lines of code end with semicolons appropriately.

[code]<html>

<head>
  <title>example</title>
  script type="text/javascript">
    function change(html) {
      description.innerHTML = html;
    }
  </script>
</head>

<body>

<a href="#" onMouseOver="javascript:change('Over link one!');" onMouseOut="javascript:change('');">Link 1</a><br />
<a href="#" onMouseOver="javascript:change('Over link two!');" onMouseOut="javascript:change('');">Link 2</a><br />
<a href="#" onMouseOver="javascript:change('Over link three!');" onMouseOut="javascript:change('');">Link 3</a><br /><hr />

<div id="description"></div>

</body>

</html>[/code]

[EDIT] Removed dollar signs..
Javascript does not like newline in the middle of code. If the variable you're passing has newlines in it it just won't work.

I think it would also help us to know what's actually in that variable that's being used in the javascript.

Archived

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

×
×
  • Create New...

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.