if statement - PHP if/else switch not working -
goal: trying rollover button state remain "on" when url equals "enhanced.php".
problem: button state not remain "on" when url equals "enhanced.php".
(button acts correctly rollover)
sidemenu.php sidemenu.php used php include on pages (i don't know if makes difference
<?php $script = $_server['script_name']; //set default state off , turn on if on current url. $enhancedstate = off; $pos = strpos($script, "enhanced.php"); if($pos === true) { $enhancedstate = on; } ?> <div class="sidemenu"> <a href="enhanced.php" onmouseout="mm_swapimgrestore()" onmouseover="mm_swapimage('image1','','/images/button_on_01.gif',1)"> <img src="/images/button_<? echo $enhancedstate; ?>_01.gif" name="image1" border="0"> </a>
anyone see reason why button state not stay "on" when current url "enhanced.php". tia
strpos
returns int on success, , false on failure.
change if($pos === true)
if($pos !== false)
.
the ===
operator compares values , types. so, on success strpos
returns int, may have same value true, it's not same type.
edit: others have said, should change:
$enhancedstate = off
$enhancedstate = 'off'
php forgiving, , let use un-quoted strings, should try not to, unless on , off constants.
Comments
Post a Comment