RE: php hide menu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dynamically changing displays can be done with JavaScript.

First thing I want you to think of is whether or not your 2nd and 3rd menus
require information from the first menu to display or sort.
According to what I see they do not.

If they do not :

We start off wrapping each of the second and 3rd menus in a DIV element and
turning them off to display. I am using 2 options pick which one is best for
you.
We can display them individually by "ID" or by the group of "class". Now we
give an ID attribute to the first menu.

echo "<select ID='market' name='term'><option value=''>Choose
Market</option>\n";

<DIV ID=Menu2 class=other_menus style="display: none;">  Put your 2nd menu
in here  </DIV>
<DIV ID=Menu3 class=other_menus style="display: none;">  Put your 3nd menu
in here  </DIV>

In this example I will utilize JQuery.js   IF you do not have it you can
download it from www.jquery.com .

Please do not use both function if you use a class use the class if you use
and ID base use the ID

<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
	
	// this will display them by ID
	$('#market').change(
		Function() {
		Val marketvalue = $(This).val();  // I am doing this because
what if they change the menu back to the default value of ''
			If(marketvalue >= 1)
			{
			$('#Menu2').show();
			$('#Menu3').show();
			}else{
			$('#Menu2').hide();
			$('#Menu3').hide();
			}
		}
	);

	// this will display them by the class
	$('#market').change(
		Function() {
		Val marketvalue = $(This).val();  // I am doing this because
what if they change the menu back to the default value of ''
			If(marketvalue >= 1)
			{
			$('.other_menus').show();
			}else{
			$('.other_menus').hide();
			}
		}
	);	
});
</script>

This will display the menu items as soon as they pick from the first menu
NOT requiring a submit.
If you do require the value from the first menu to be passed to the select
statements for the other menus let me know I will explain how that is done,
it is a little more complex.


Richard L. Buskirk


-----Original Message-----
From: Chris Stinemetz [mailto:chrisstinemetz@xxxxxxxxx] 
Sent: Tuesday, June 07, 2011 12:41 AM
To: php-general@xxxxxxxxxxxxx
Subject:  php hide menu

I have three drop down menus in my form. How do I make it so the
second and third menus are only visible once the prior menu was
selected?

Below is the first two drop down menus.

Thanks in advance.

// Generating first menu using array.
$markets = array('MCI' => 'Kansas City',
                          'STL' => 'ST. Louis',
	          'ICT' => 'Wichita',
	          'OMA' => 'Omaha',
                          'LIN' => 'Lincoln');
echo "<select name='term'><option value=''>Choose Market</option>\n";
foreach ($markets as $key => $market) {
	echo "<option value='$key'>$market</option>\n";
}
echo "</select>";

// This will evaluate to TRUE so the text will be printed.
if (isset($markets)) {
    echo "This var is set so I will print.";
}



// Then, later, validating the menu
if (! array_key_exists($_POST['Market'], $choices)) {
	echo "You must select a market.";
}

$query="SELECT cell_sect FROM sector_list order by cell_sect";

$result = mysql_query ($query);
echo "<select name='cat'><option value=''>Choose Cell Sector</option>";
// printing the list box select command

while($cellSect=mysql_fetch_array($result)){//Array or records stored
in $cellSect
echo "<option value=$cellSect[cell_sect]>$cellSect[cell_sect]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box

// This will evaluate to TRUE so the text will be printed.
if (isset($cellSect)) {
    echo "This var is set so I will print.";
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux