PHP jump menu (without JavaScript??)
Posted: Mon Aug 25, 2008 12:14 pm
Hey guys,
I can't for the life of me find help on this anywhere so thought I'd try my luck here! So here goes...
ISSUES:
First issue:
I have created a simple jump menu to dynamically switch content via the use of php variables. But the jump menu itself relies on JavaScript.
Is there any way of creating a PHP replacement for the Javascript? Currently if Javascript is turned off, the jump menu doesn't work so that's no good for the users.
Second issue:
When you select a link from the jump menu, lets say 'Link 02', it works fine and dynamically displays the Link 02 content via the use of variables but then the jump menu list switches back to LINK rather than showing the current selected item, which should be 'Link 02' in this case.
I know you can simply use the "selected="selected" value but I need a way to add this value dynamically only when a particular link from the jump menu has actually been selected. I presume the use of a simple <?php echo 'selected="selected"'; ?> can be added to the jump menu item but it needs to be echoed only IF a particular item is selected so the use of a conditional statement might be in order but I'm pretty new to PHP so its proving difficult. Would appreciate a hand?
CODE:
Template.php (main page and without additional HTML markup):
Menu.php (the jump menu itself is pretty simple and is included via a php include):
The JavaScript used to make the jump menu function (created automatically via Dreamweaver) is:
If any of you guys could shed some light on this or help out or even point me in the right direction I would really appreciate it.
Cheers in advance,
Darren
I can't for the life of me find help on this anywhere so thought I'd try my luck here! So here goes...
ISSUES:
First issue:
I have created a simple jump menu to dynamically switch content via the use of php variables. But the jump menu itself relies on JavaScript.
Is there any way of creating a PHP replacement for the Javascript? Currently if Javascript is turned off, the jump menu doesn't work so that's no good for the users.
Second issue:
When you select a link from the jump menu, lets say 'Link 02', it works fine and dynamically displays the Link 02 content via the use of variables but then the jump menu list switches back to LINK rather than showing the current selected item, which should be 'Link 02' in this case.
I know you can simply use the "selected="selected" value but I need a way to add this value dynamically only when a particular link from the jump menu has actually been selected. I presume the use of a simple <?php echo 'selected="selected"'; ?> can be added to the jump menu item but it needs to be echoed only IF a particular item is selected so the use of a conditional statement might be in order but I'm pretty new to PHP so its proving difficult. Would appreciate a hand?
CODE:
Template.php (main page and without additional HTML markup):
Code: Select all
<?php
//Include menu
include('menu.php');
//Get the page variable
$page = $_GET['page'];
//Our switch statement to get the right content
switch($page) {
case "01":
$content = "01.html";
break;
case "02":
$content = "02.html";
break;
case "03":
$content = "03.html";
break;
case "04":
$content = "04.html";
break;
default: //If the variable didn't match any of the above cases do this.
$content = "01.html";
break;
}
//Include the selected content.
include($content);
?>Code: Select all
<form>
<select name="LINK" onChange="jumpMenu('parent',this,0)">
<option value="template02.php">LINK</option>
<option value="template02.php?page=01">Link 01</option>
<option value="template02.php?page=02">Link 02</option>
<option value="template02.php?page=03">Link 03</option>
<option value="template02.php?page=04">Link 04</option>
</select>
</form>Code: Select all
<!-- JUMP MENU
function jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
Cheers in advance,
Darren