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
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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.