javascript - Dynamically Select An HTML option based previous select option
问题描述
How do you dynamically select an HTML option based on a previous select tag? Image of current project
Below is the code I have done to get there. I expect the size select tag to be disabled until a user selects a colour like Neon Blue and then the size option tag populates all the sizes that are available for that specific color like this like this
<!-- product attributes -->
<div class="product-attributes">
<select class="product-select-attributes" name="p-attrib" id="p-attrib">
<?php
echo "<option selected disabled>Color</option>";
//echo "<option value={$productID}>$color</option>";
foreach($arrays as $nxt) {
//echo "<option value={$nxt['pID']}>{$nxt['attrib']} <p> | </p> {$nxt['quantity']} <p>left</p></option>";
echo "<option value={$productID}>{$nxt['color']}</option>";
}
?>
</select>
<br>
<hr>
<select class="product-select-attributes" name="p-attrib" id="p-attrib">
<?php
echo "<option selected disabled>Size</option>";
foreach($arrays as $nxt) {
//echo "<option value={$nxt['pID']}>{$nxt['attrib']} <p> | </p> {$nxt['stock']} <p>left</p> </option>";
echo "<option value={$productID}>{$nxt['size']}</option>";
}
?>
</select>
</div>
<!-- add to cart button -->
<div class="product-add-to-cart">
<div class="product-atc">
<a href="#">Add To Cart</a>
</div>
</div>
解决方案
推荐阅读
- android - 无法获得 Google 云端硬盘授权
- scala - 在 Apache spark 中读取包含分隔符的值的 CSV 文件
- c++ - 如何获取泛型 lambda 的返回类型和参数类型?
- c++ - 即使我使用字符串空格,也使用 >> 和 getline 获取空输出
- angular - 手动角度运行类型检查
- excel - 我找不到将 excel 文件读入 pyspark 数据框的代码
- c# - 如何将 JObject 插入 MongoDB?
- pdf - Xamarin 表单:Word 文档未在 ios 应用程序中打开
- json - 通过 Azure Datafactory V2 将 XML 与 REST API 结合使用
- identityserver4 - 如何通过 IdentityServer 连接到 Azure B2c