簡體   English   中英

在php中選擇其他搜索選擇標記時填充其他文本框

[英]populate other textboxes on selection of other search select tag in 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM