ALS
11-29-2002, 10:48 PM
I am trying to link two drop-down menus, I have searched high and low for a script to do this using PHP without any success. As i’m new to programming and PHP I don’t really know where to start. I have had a go and came up with the following... (see below)
Unfortunately this doesn’t work how I intended, what I want to happen is when a choice is made from the top menu the second menu will automatically display the relevant models of car for the chosen manufacturer. As you can see, what actually happens is you get ALL of the models being displayed in the second drop-down menu.
Any help with this will be much appreciated, as I seem to be going round in circles at the moment. If there is another way of resolving this without using arrays I am all ears.
cheers
ALS
<html>
<head>
<title>Linked drop down menu</title>
<body>
<form name="form1" method="post" action="">
<select name="manufacturer">;
<?php
$manufacturer=array("ANY","AC","AXIM","ALFA ROMEO");
foreach( $manufacturer as $manu_value)
{ echo("<option>$manu_value</option>");}
?>
</select>
<br>
<select name="model">;
<?
//define variables
$any=array("ANY");
$ac=array("ACE","COBRA","SUPERBLOWER");
$axim=array("400","500");
$alfa_romeo=array("145","146","147","155","156","164","166","33","75",
"ALFASUD","GIULIETTA","GTV","SPIDER","SPORTWAGON","SPRINT");
if ($manu_value == "ANY")
foreach ( $any as $any_value)
{ echo("<option>$any_value</option>");}
else if ($manu_value == "AC")
foreach ( $ac as $ac_value)
{ echo("<option>$ac_value</option>");}
else if ($manu_value == "AXIM")
foreach ( $axim as $axim_value)
{ echo("<option>$axim_value</option>");}
else if ($manu_value == "ALFA ROMEO")
foreach ( $alfa_romeo as $alfa_romeo_value)
{ echo("<option>$alfa_romeo_value</option>");}
?>
</form>
</body>
</html>
Unfortunately this doesn’t work how I intended, what I want to happen is when a choice is made from the top menu the second menu will automatically display the relevant models of car for the chosen manufacturer. As you can see, what actually happens is you get ALL of the models being displayed in the second drop-down menu.
Any help with this will be much appreciated, as I seem to be going round in circles at the moment. If there is another way of resolving this without using arrays I am all ears.
cheers
ALS
<html>
<head>
<title>Linked drop down menu</title>
<body>
<form name="form1" method="post" action="">
<select name="manufacturer">;
<?php
$manufacturer=array("ANY","AC","AXIM","ALFA ROMEO");
foreach( $manufacturer as $manu_value)
{ echo("<option>$manu_value</option>");}
?>
</select>
<br>
<select name="model">;
<?
//define variables
$any=array("ANY");
$ac=array("ACE","COBRA","SUPERBLOWER");
$axim=array("400","500");
$alfa_romeo=array("145","146","147","155","156","164","166","33","75",
"ALFASUD","GIULIETTA","GTV","SPIDER","SPORTWAGON","SPRINT");
if ($manu_value == "ANY")
foreach ( $any as $any_value)
{ echo("<option>$any_value</option>");}
else if ($manu_value == "AC")
foreach ( $ac as $ac_value)
{ echo("<option>$ac_value</option>");}
else if ($manu_value == "AXIM")
foreach ( $axim as $axim_value)
{ echo("<option>$axim_value</option>");}
else if ($manu_value == "ALFA ROMEO")
foreach ( $alfa_romeo as $alfa_romeo_value)
{ echo("<option>$alfa_romeo_value</option>");}
?>
</form>
</body>
</html>