我正在使用两个选择,一个作为类别,第二个作为子类别。我希望使第二个选择菜单由在第二个选择菜单中选择的选项来确定。
这是 html/php 代码。
<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>
我想要它,所以当您从类别中选择一个选项时,它将显示正确的选项以显示在<select>
.
我不确定您是否可以做到这一点,但如果有人有想法或知道如何做到这一点,您的帮助将会有所帮助。