Creating a Series of Dropdown Menus

Hi there, i’m trying to create a series of dropdown menus to respond like this

–Pick a Category
-Acrylic
-Gelcoat
-Options

Upon selecting one of the above dropdown items i would like a new dropbox menu to appear:
–Select Fixture
-Bathtub
-Shower
-Special Needs

This is the way that i tried to do it , but i think it’s looking for an action button to make this work…

[code]
Select Category
Acrylic
Gelcoat
System Connects
Options

					<? if ($_POST[category] == "acrylic") {
					echo 	"<select name=\"acrylic_prod\">";
					echo "<option value=\"NULL\">Select Fixture</option>";
					echo "<option value=\"ac_bw\">Bath & Whirlpool</option>";
					echo "<option value=\"ac_bs\">Bath/Showers</option>";
					echo "<option value=\"ac_shwr\">Showers</option>";
					echo "<option value=\"ac_recept\">Receptors</option>";
					echo "<option value=\"ac_sn\">Special Needs</option>";
					echo "</select>";
					}?>[/code]

First of all sorry about my english.

At second select you put,
<? if ($_POST[category] == “acrylic”) {

This only works if you select “acrylic” at first select and send values to php.

To do this you must use an form.

Try :
[php]

Select Category Acrylic Gelcoat System Connects Options
              <? if ($_POST[category] == "acrylic") {
              echo    "<select name=\"acrylic_prod\">";
              echo "<option value=\"NULL\">Select Fixture</option>";
              echo "<option value=\"ac_bw\">Bath & Whirlpool</option>";
              echo "<option value=\"ac_bs\">Bath/Showers</option>";
              echo "<option value=\"ac_shwr\">Showers</option>";
              echo "<option value=\"ac_recept\">Receptors</option>";
              echo "<option value=\"ac_sn\">Special Needs</option>";
              echo "</select>";
              }?>

[/php]

There is another solution to show 2 select if this has static you can hide this (“style=‘display:none’”) ans show this in onchange of 1st select.

If there is no static, you can refresh data with AJAX request.

Thanks for the response, i should have included the entire code, i have a form for submitting the entire page already…

[php]

Create New Quote
Select Your Region:
<br><input type="Radio" name="region" value="HLM"> Lower Mainland
<br><input type="Radio" name="region" value="HOP"> Interior
<br><input type="radio" name="region" value="HIP"> Island

<p>Project Name:
	<br><input type ="text" name="project" cols=30 rows=1></textarea></p>
	

City:
	<br><textarea name="city" cols=30 rows=1></textarea>
	<p>
Builder:
<br><textarea name="builder" cols=30 rows=1></textarea></p>
<p>Contractor:
<br><textarea name="contractor" cols=30 rows=1></textarea></p>
<p>Engineer:
	<br><textarea name="engineer" cols=30 rows=1></textarea></p>
	<p>Distributor:
		<br><select name="distributor"><option value="">Pick One</option>
			<option value="asl">Andrew Sheret Ltd</option>
			<option value="bar">BA Robinson</option>
			<option value="bg">Bartle & Gibson</option>
			<option value="emco">Emco Corporation</option>
			<option value="noble">Noble Supply</option>
			<option value="universal">Universal Supply</option>
			<option value="wolseley">Wolseley</option>
			</select>
		<p>Branch:
			<br><textarea name="branch" cols=30 rows=1></textarea></p>
			<P>Attention:
			<br><textarea name="attention" cols=30 rows=1></textarea></p>
	<p>Date:
		<br><textarea name="date" cols=30 rows=1></textarea></p>
		<p>Date Expired:
			<br><textarea name="dateexp" cols=30 rows=1></textarea></p>
			<form method="post" name="cats">
				<select name="category">
					<option value="">Select Category</option>
					<option value="acrylic">Acrylic</option>
					<option value="gelcoat">Gelcoat</option>
					<option value="systems">System Connects</option>
					<option value="options">Options</option>
					</select>
					
					<? if ($_GET[category] == "acrylic") {
					echo 	"<select name=\"acrylic_prod\">";
					echo "<option value=\"NULL\">Select Fixture</option>";
					echo "<option value=\"ac_bw\">Bath & Whirlpool</option>";
					echo "<option value=\"ac_bs\">Bath/Showers</option>";
					echo "<option value=\"ac_shwr\">Showers</option>";
					echo "<option value=\"ac_recept\">Receptors</option>";
					echo "<option value=\"ac_sn\">Special Needs</option>";
					echo "</select>";
					}
					?>
					
			
		
				</form>
		
				<input type="submit" name="submit" value="Create Quote">
				</form>
</body>
</html>[/php]

So when i open this up and select Acrylic it SHOULD create a new dropdown menu containing Bath & Whirlpool,Bath, Showers, etc… but it doesnt , no error , it just doesnt do anything.

I made some changes to reflect more how you suggested , but the new dropdown still doesnt come up…

[php]

Create New Quote
Select Your Region:
<br><input type="Radio" name="region" value="HLM"> Lower Mainland
<br><input type="Radio" name="region" value="HOP"> Interior
<br><input type="radio" name="region" value="HIP"> Island

<p>Project Name:
	<br><input type ="text" name="project" cols=30 rows=1></textarea></p>
	

City:
	<br><textarea name="city" cols=30 rows=1></textarea>
	<p>
Builder:
<br><textarea name="builder" cols=30 rows=1></textarea></p>
<p>Contractor:
<br><textarea name="contractor" cols=30 rows=1></textarea></p>
<p>Engineer:
	<br><textarea name="engineer" cols=30 rows=1></textarea></p>
	<p>Distributor:
		<br><select name="distributor"><option value="">Pick One</option>
			<option value="asl">Andrew Sheret Ltd</option>
			<option value="bar">BA Robinson</option>
			<option value="bg">Bartle & Gibson</option>
			<option value="emco">Emco Corporation</option>
			<option value="noble">Noble Supply</option>
			<option value="universal">Universal Supply</option>
			<option value="wolseley">Wolseley</option>
			</select>
		<p>Branch:
			<br><textarea name="branch" cols=30 rows=1></textarea></p>
			<P>Attention:
			<br><textarea name="attention" cols=30 rows=1></textarea></p>
	<p>Date:
		<br><textarea name="date" cols=30 rows=1></textarea></p>
		<p>Date Expired:
			<br><textarea name="dateexp" cols=30 rows=1></textarea></p>
			<form method="post" name="cats">
				<select name="category" onchange='document.cats.submit()'>
					<option value="">Select Category</option>
					<option value="acrylic">Acrylic</option>
					<option value="gelcoat">Gelcoat</option>
					<option value="systems">System Connects</option>
					<option value="options">Options</option>
					</select>
					
					<? if ($_POST[category] == "acrylic") {
					echo 	"<select name=\"acrylic_prod\">";
					echo "<option value=\"NULL\">Select Fixture</option>";
					echo "<option value=\"ac_bw\">Bath & Whirlpool</option>";
					echo "<option value=\"ac_bs\">Bath/Showers</option>";
					echo "<option value=\"ac_shwr\">Showers</option>";
					echo "<option value=\"ac_recept\">Receptors</option>";
					echo "<option value=\"ac_sn\">Special Needs</option>";
					echo "</select>";
					}
					?>
					
			
			<?
			$db_name = "productdata";
			$table_name = "ptb";
			$connection = @mysql_connect("localhost", "craigrasmussen", "belladog") or die(mysql_error());
			$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
			  
			echo    "<select name =\"product\">\n";	
			echo    "<option value=\"NULL\">Select Value</option>\n";
			
			$sql = "SELECT prod_sku FROM $table_name ORDER BY prod_sku";
			$result = @mysql_query($sql, $connection) or die(mysql_error());
			while ($row = mysql_fetch_array($result)) {
				$sku = $row['prod_sku'];
				echo "<option value=\"$sku\"> $sku </option>"; 
	}			
	echo "</select>";

				?>
				</form>
		
				<input type="submit" name="submit" value="Create Quote">
				</form>
</body>
</html>[/php]

Do you want the new dropdown box to appear as soon as “Acrylic” has been selected or on a different page? If you are testing for “acrylic” in PHP then the user will have to submit the form before it is tested for and the extra dropdown box is added.

Yeah I’d like to do it on the same page… I guess the only way I can do this is with JavaScript? I tried that way as well but still having difficulty, I’ll post the code for my JavaScript portion maybe someone can help me figure out whats going on with it

You can refresh data with AJAX request.

Ajax javascript used to reload parts of the page, without ever reloading the entire page.
Ajax is used from javascript.

Javascript code running on the client, while the php interpreter is done on the server, ajax performs a mix because even if performed on the client makes requests that are interpreted in the server and are used in customer.

This technique is already practically indispensable for new sites.

This technique can be more complex to use than the techniques used to check fields and others. But there Frameworks javascript that makes it much easier to use.

To my taste the best JQuery, since the use is simple and has a great gallery plugins another is very good prototype. Seek on google and you will see that will enhance any web

Sponsor our Newsletter | Privacy Policy | Terms of Service