Example 1
The button is a blob of colour (.jpg) with text over the top. I want two things to happen: first, when the cursor is rolled over the .jpg and then the text, I want the text to change colour. This works ok.
Second, I want to link to industry.php when clicked. This works ok over the .jpg but, obviously, not over the text.
echo '<div id="industry_button"><a href="industry.php" onmouseover="Roll_Industry(true)" onmouseout="Roll_Industry(false)">
<img name="Industry" src="graphics/industry_button.jpg" width="133" height="30" /></a>
<div class="text" onmouseover="Roll_Industry(true)" onmouseout="Roll_Industry(false)">Industry</div>
</div>';
#industry_button
{
position:relative;
top:60px;
left:-100px;
float:left;
font-size:14px;
color: #066;
}
#industry_button .text
{
position:absolute;
top:7px;
left:10px;
float:left;
cursor:pointer;
}
function Roll_Industry(mouse)
{
if (mouse == true)
{
document.getElementById("industry_button").style.color="red";
}
else
{
document.getElementById("industry_button").style.color= "#066";
}
}
Example 2
Similar to Example 1 with <a> tag around the text. The linking is now ok but the colour change does not occur when the cursor is over the .jpg It does change colour when the cursor is over the text.
I suspect that my problem lies with the Javascript. The alert's show that the javascript is being executed.
echo '<div id="home_button"><a href="index.php" onmouseover="Roll_Home(true)" onmouseout="Roll_Home(false)">
<img name="home" src="graphics/home_button.jpg" width="65" height="30" /></a>
<div class="text" ><a href="index.php" onmouseover="Roll_Home(true)" onmouseout="Roll_Home(false)"> Home</a>
</div>
</div>';
#home_button
{
position:relative;
top:60px;
left:-120px;
float:left;
font-size:14px;
}
#home_button .text
{
position:absolute;
top:7px;
left:10px;
float:left;
cursor:pointer;
}
#home_button .text a
{
color:#fff;
}
#home_button .text a:hover
{
color:#ff0000;
}
function Roll_Home(mouse)
{
if (mouse == true)
{
alert("foo");
elem1 = document.getElementById("home_button");
elem1.firstChild.a.style.color="red";
}
else
{
alert("foo1");
document.getElementById("home_button").a.style.color= "#fff";
}
}