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
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..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.