View Full Version : This menu without javascsript?

08-24-2007, 03:15 PM
The code below is my navigation div. I would like to see how I can do the same thing without the javascript. I can't see how I can set the value on a click without it though.

<script type="text/javascript">
function menuops(strchoice)
var frmField=document.getElementById? document.getElementById("menuForm"): document.all.menuForm;

<div id="menu">
<?php // Set up loop to read menu items from the DB and put them here.

$query = "SELECT itemName, itemLink FROM menu WHERE itemAttribute='Y' ORDER BY itemPriority ASC";
$result = mysql_query($query) or die ("Error in menu query: $query. ".mysql_error());
if (mysql_num_rows($result) > 0){
echo "<ul id=\"menulist\">";
while ($row=mysql_fetch_array($result)){
print "<li";
if ($thispage==$row['itemLink']) print " id=\"currentpage\"";
print " onclick=menuops(\"".$row['itemLink']."\")>".$row['itemName']."</li>";
else {
// no
// print status message
echo "No rows found!";

<div id="menuFormDiv" visible="false">
<form action="index.php" id="menuForm" method="post">
<input type="hidden" name="menuaction">

08-24-2007, 05:23 PM
Submitting a form with a hidden input set to a certain value isn't possible in PHP.

If you cannot depend on the existance of JavaScript on the client (pretty much everyone has it), then you should consider trying something else. For example, basic HTML links (A). You can style them like your LI elements, and no one will know the difference.

Unless you need the Form to submit other things as well. But from what you gave, you just have a specific action sent when the user clicks on a specific LI. This is easily replaced by my suggestion of using the A tag.

08-24-2007, 05:29 PM
That's what I thought. I'll just have to stick with what I have and require the user to allow javascript while browsing my pages.

Thanks for your response.