I am using two selects, the one as the category and the second one as subcategory. I wish to make the second select menu to be determined by what option was chosen in the second select menu.
Here is the html/php code.
<select name="category" id="category">
<?php
$options = array("Stationary", "Bag", "Paper");
foreach ($options as $option) {
echo '<option value"' . $option . '"';
if(in_array($option, $category)){
echo " Selected";
}
echo ">" . ucfirst($option) . "</option>";
}
?>
</select>
<select name="subcategory" id="subcategory">
<?php
$options = array("Pencils", "Ruler", "Pens");
foreach ($options as $option) {
echo '<option value"' . $option . '"';
if(in_array($option, $category)){
echo " selected";
}
echo ">" . ucfirst($option) . "</option>";
}
?>
<?php
$options = array("Small", "Large", "Paper");
foreach ($options as $option) {
echo '<option value"' . $option . '"';
if(in_array($option, $category)){
echo " selected";
}
echo ">" . ucfirst($option) . "</option>";
}
?>
<?php
$options = array("Notepad", "Plain ", "Colour");
foreach ($options as $option) {
echo '<option value"' . $option . '"';
if(in_array($option, $category)){
echo " selected";
}
echo ">" . ucfirst($option) . "</option>";
}
?>
</select>
I want it so when and you select one option from category it will it show the correct options to be shown in the <select>
.
I'm not sure if you can do this, but if anyone has an idea or know how to do this your help would be helpful.