art15 Posted July 12, 2008 Share Posted July 12, 2008 Hi, I have a drop down box which allows user to navigate through pages <form name="visit" style="font-size: 9pt;"> <select name="selectname" SIZE="1" onChange="change()"> <option value="">Change Page</option> <option value="index.php"> Home Page</option> <option value="page2.php">News</option> <option value="page3.php">Rss</option> </select> </form> <script language="JavaScript"> function change() { var url = document.visit.selectname.options[document.visit.selectname.selectedIndex].value window.location.href = url } </script> The page switches perfectly, however once you reach the page selected, the drop down says "change page". i would like it to say the option selected like if user selects Rss it should say Rss. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/ Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 try this <?php $page = basename($_SERVER['SCRIPT_NAME']); $pageArray = array("index.php"=>"Home Page", "page2.php"=>"News", "page3.php"=>"Rss"); ?> <form name="visit" style="font-size: 9pt;"> <select name="selectname" SIZE="1" onChange="change()"> <option value="">Change Page</option> <?php foreach($pageArray as $key=>$value){ if($key == $page){ print "<option value=\"".$key."\" selected>".$value."</option>"; } else { print "<option value=\"".$key."\">".$value."</option>"; } } ?> </select> </form> <script language="JavaScript"> function change() { var url = document.visit.selectname.options[document.visit.selectname.selectedIndex].value window.location.href = url } </script> Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588206 Share on other sites More sharing options...
Ken2k7 Posted July 12, 2008 Share Posted July 12, 2008 Using PHP for this may not be the best way of doing it. It's just more writing. xHTML and JavaScript will suffice. =) Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588220 Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 may be.... but it will javascript independent Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588227 Share on other sites More sharing options...
GingerRobot Posted July 12, 2008 Share Posted July 12, 2008 Personally, i wouldn't call something which relies on a javascript function 'javascript independant', but yeah. Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588230 Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 and moreover what is the need to try it on client side if it is possible from server side..... Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588232 Share on other sites More sharing options...
Ken2k7 Posted July 12, 2008 Share Posted July 12, 2008 and moreover what is the need to try it on client side if it is possible from server side..... ??? I don't quite know what you're talking about. Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588236 Share on other sites More sharing options...
Third_Degree Posted July 12, 2008 Share Posted July 12, 2008 and moreover what is the need to try it on client side if it is possible from server side..... ??? I don't quite know what you're talking about. I guess he's saying since JS is not always turned on in a client browser, php will always be able to do it. Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588237 Share on other sites More sharing options...
Ken2k7 Posted July 12, 2008 Share Posted July 12, 2008 I guess he's saying since JS is not always turned on in a client browser, php will always be able to do it. Oh well not really. PHP can't redirect a user upon a user action, so for this type of code, JavaScript has to be enabled. There's always the <noscript> tag. =) Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588242 Share on other sites More sharing options...
Third_Degree Posted July 12, 2008 Share Posted July 12, 2008 Well for the task of changing what option is first in the dropdown menu, php is adequate, but yes JS will be needed for the rest. Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588249 Share on other sites More sharing options...
Ken2k7 Posted July 12, 2008 Share Posted July 12, 2008 Well for the task of changing what option is first in the dropdown menu, php is adequate, but yes JS will be needed for the rest. What about plain old xHTML for the dropdown? Quote Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.