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? 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> 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. =) 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 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. 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..... 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. 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. 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. =) 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. 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? Link to comment https://forums.phpfreaks.com/topic/114380-drop-down-help/#findComment-588255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.