Jump to content

Recommended Posts

Hi

i am trying to create something that when you hover over some text then the div changes colour. I am using php to get the data from a mysql table and then javascript to change the div backgroundcolor when it is hovered over. Here is the main code in the body:

<?php
$games = mysql_query("SELECT * FROM `games`");
while ($rows = mysql_fetch_array($games)) { 
echo "<div id='game".$rows['gamenumb']."'style='background-color: #333333;width: 750; '><a href='http://www.rasclerhys.com/playgames.php?id=".$rows['gamenumb']."' ><img src='".$rows['picture']."' border='0' width='70' height='59'></a>
<a href='http://www.rasclerhys.com/playgames.php?id=".$rows['gamenumb']."' onMouseOver='javascript:changeBG(0,game".$rows['gamenumb'].")' onMouseOut='javascript:changeBG(1,game".$rows['gamenumb'].")'>".$row['text']."</a></div><br />";}
?>

Here is the javascript code in the head:

<script language="Javascript">
<!--

var backColor = new Array();
backColor[0] = '#666666';
backColor[1] = '#333333';

function changeBG(whichColor,gameid){
document.getElementById(gameid).style.backgroundColor = backColor[whichColor];
}

//-->
</script>

The data is being displayed fine, but when i hover over the link the background color (of the div) does not change,

does anybody know how to correct this???

Thanks in advance

:)

Link to comment
https://forums.phpfreaks.com/topic/168779-solved-getelementbyid-problem/
Share on other sites

yes but i need to use javascript because later on i want to add a feature that when you hover over the link aswell as the background div changing, some other text (previously hidden) appears. is there a way to get the code above to work(from the first post)?

Also i am using php to get the info from the database and since it is being constantly updated i would have to manually add hundreds of lines of

div.game1.hover

div.game2.hover

div.game3.hover

etc

since u cant have a while loop in css... right?

 

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.