Jump to content

Drop down help.


art15

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.