Jump to content

Archived

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

princessdeia

mySQL and JavaScript Image Rollovers

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

Share this post


Link to post
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..

Share this post


Link to post
Share on other sites
<shudder> Prefixing JS variables with dollar signs? </shudder>

Share this post


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

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.