如何获取选择值的值


How to get the value of a Select value

如何

获取动态填充的选择按钮的选项值,以便我可以用来获取数据库中所需的值。我不知道如何获取$giftName值。我尝试使用jquery和javascript,但我不知道如何将其集成到我的代码中,因为我仍然是这种语言的新手。以下是我的代码的一部分,可能会对您有所帮助:

<div class="row ml ">
    <div class="col-lg-6 ">
        <select id="giftList" name=''gifts" class="pull-left mb">
            <option value=""></option>
                <?php 
                    $sendGiftSql = mysql_query("SELECT * FROM gifts WHERE isDelete = 'false' ORDER BY price ");
                    while($sendGift = mysql_fetch_assoc($sendGiftSql)){
                        $giftName = $sendGift['name'];
                       echo("
                            <option value =". $giftName.">"  . $giftName. "</option>;
                       ");
                    }
                ?>
            </select>
        </div>
        <div class="col-lg-6">
            <b style="float: right;">Cost://This is where the value of the select button will be used...
        </div>
    </div>

更改此内容

<option>" . $giftName. "</option>;

echo("<option value =". $giftName.">" . $giftName. "</option>");

稍后,您可以使用 $('#giftList') 获取所选值。