
December 26th, 2004, 01:21 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 4
|
|
|
PHP Newbie - hover button help
Hi, just learning PHP and I'm creating a menu, I kind of cheated and got Frontpage to make the basic code for a hover button as I don't know jscript - but it works, at least when it was in HTML. Now the menu displays fine, and hovering and click the button changes the image right, but the OnMouseOut attrib seems to be dead. Here're the bits of my code:
this is in the head:
Code:
<script language="JavaScript">
<!--
function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}
function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}
}
}
var preloadFlag = false;
function preloadImages() {
if (document.images) {
akdor_Button_over = newImage("images/menu/akdor-Button_over.png");
akdor_Button_down = newImage("images/menu/akdor-Button_down.png");
downloads_Button_down
newImage(images/menu/downloads-Button_over.png");
downloads_Button_over =
newImage(images/menu/downloads-Button_down.png");
preloadFlag = true;
}
}
//-->
</script>
and later on (after <body onload="preloadImages();">)
PHP Code:
<?php
$section = "akdor";
function makemenuitem ($itemname) {
global $section;
$menuitemcurrent = '<img name="$preitemname_Button" src="images/menu/$preitemname-Button_selected.png" width="100" height="30" border="0"></a><br />' . "\n";
$menuitembutton =
'<a href="$preitemname.php"' . "\n" . 'onMouseOver="changeImages(\'$preitemname_Button\', \'images/menu/$preitemname-Button_over.png\'); return true;"' . "\n" .
'onMouseOut="changeImage(\'$preitemname_Button\', \'images/menu/$preitemname-Button.png\'); return true;"' . "\n" .
'onMouseDown="changeImages(\'$preitemname_Button\', \'images/menu/$preitemname-Button_down.png\'); return true;"' . "\n" .
'onMouseUp="changeImages(\'$preitemname_Button\', \'images/menu/$preitemname-Button_over.png\'); return true;">' . "\n" .
'<img name="$preitemname_Button" src="images/menu/$preitemname-Button.png" width="100" height="30" border="0"></a><br />' . "\n";
if ($section == $itemname) {
$menuitemcurrent = str_replace ('$preitemname', $itemname, $menuitemcurrent);;
print ($menuitemcurrent);
} else {
$menuitembutton = str_replace ('$preitemname', $itemname, $menuitembutton);
print ($menuitembutton);
}
}
makemenuitem ('akdor');
makemenuitem ('downloads');
?>
For the sake of legibillity, I've just made line breaks when defining $menuitembutton, in my code it's just one line.
It's meant to create a hover button, for all menu items except the one that links to the current page; in which case it just displays an orange menu item pic (instead of blue  ).
Any help would be appreciated. 
|