javascript - 在 php 中选择其他搜索选择标签时填充其他文本框
问题描述
我想在 PHP 中选择搜索选择标签时填充其他文本框。
<div class="col-md-6">
<?php include "dbcon.php";
$con = connect();
$get=mysqli_query($con,"SELECT product_name FROM purchases_sales ORDER BY product_name ASC");
$option = '';
while($row = mysqli_fetch_assoc($get)){ $option .= '<option data-tokens="'.$row['product_name'].'" value="'.$row['product_name'].'" >'.$row['product_name'].'</option>';}?>
<label>Product Name</label>
<select class="selectpicker" data-show-subtext="true" data-live-search="true" name="<option value="0" selected disabled>- Select Product Name-</option><?php echo $option; ?></select>
</div>
<div class="col-md-6">
<label>Product Type</label>
<select class="form-control" name="product_type">
<option value="Raw">Raw</option>
<option value="Fried">Fried</option>
<option value="Marinated">Marinated</option>
</select>
</div>
<div class="col-md-4">
<label>Product ID</label>
<input type="number" class="form-control" placeholder="Product ID" name="product_id">
</div>
<div class="col-md-4">
<label>Selling Price</label>
<input type="number" class="form-control" placeholder="Selling Price" name="">
</div>
<div class="col-md-4">
<label>Quantity</label>
<input type="number" class="form-control" placeholder="Quantity" name="">
</div>
<div class="col-md-6" style="margin-top:10px;">
<input type="submit" value="Add" name="add_product" class="form-control">
</div>
解决方案
我不知道在选择下拉列表后要填充什么,但也许这将有助于使用库 jquery。
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$('#idofyourselect').on('change', function(){
var selected = $('#idofyourselect').val();
if (selected.valueOf() == "Raw"){
//do something here if Raw is selected
console.log("you selected Raw")
}
if (selected.valueOf() == "Fried"){
//do something here if Raw is selected
console.log("you selected Fried")
}
if (selected.valueOf() == "Marinated"){
//do something here if Raw is selected
console.log("you selected Marinated")
}
});
</script>
推荐阅读
- node.js - npm install:如何跳过已安装的全局包?
- c# - PictureBox 显示图像
- pagination - DataTables 使用不同的 pageLength 参数重新加载表
- angular-cli - Angular CLI 1.7.4 TypeError:无法读取 null 的属性“配置”
- javascript - 使用 jQuery select2 设置多个值
- android - 字符串资源中的特殊字符不会显示在警报对话框 (Android) 中
- magento - Magento 2 - 添加类别属性
- rest - Optaplanner 7.9.0 无法解组输入字符串错误调用 REST API
- apache - Apache 从 TLSv1.0 重定向到 TLSv1.2
- odoo-8 - 如何更新 invoice.line 数量?