Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts

    This menu without javascsript?

    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.
    Code:
    <script type="text/javascript">
    <!--
    function menuops(strchoice)
    {
    	var frmField=document.getElementById? document.getElementById("menuForm"): document.all.menuForm;
    	frmField.menuaction.value=strchoice;
    	frmField.submit();
    }
    //-->
    </script>
    
    <div id="menu">
    <?php // Set up loop to read menu items from the DB and put them here.
    
    	$db=openDB();
    	$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>";
    		}
    		mysql_close();
    	}
    	else { 
    		// no 
    		// print status message 
    		echo "No rows found!"; 
    	}
    ?>
      </ul>
    </div>
    
    <div id="menuFormDiv" visible="false">
       <form action="index.php" id="menuForm" method="post">
       <input type="hidden" name="menuaction">
       </form>
    </div>
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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.

  • Users who have thanked aedrin for this post:

    ScottInTexas (08-24-2007)

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    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.
    Scott Stewart
    Always happy to learn from pros.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •