从Bootstrap SelectPicker获取所选值

时间:2019-04-05 09:20:33

标签: javascript jquery ajax

我有一个脚本,该脚本使用the Bootstrap SelectPicker plug-in选择我喜欢的咖啡。

提交表单后,我想存储选择的值并发送到addCoffee.php?coffee=${coffee}。我该怎么做?

HTML:          

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>

<div class="container">

  <div class="row">

    <!-- Multiple Item Picker -->
    <div class="jumbotron">
        <h2>Multiple Item Picker</h2>
        <select id="coffee" class="selectpicker show-menu-arrow" 
                data-style="form-control" 
                data-live-search="true" 
                title="-- Select your coffee --"
                multiple="multiple">
        <option data-tokens="Espresso">Espresso</option>
        <option data-tokens="Americano">Americano</option>
        <option data-tokens="Mocha">Mocha</option>
        <option data-tokens="Capuccino">Capuccino</option>
        <option data-tokens="Affogato">Affogato</option>
        <option data-tokens="Long Black">Long Black</option>
        <option data-tokens="Macchiato">Macchiato</option>
        </select>

        <p></p><input type="submit" id="submit" name="submit" value="Submit"></p>

    </div><!--.jumbotron-->

  </div><!--.row-->

</div><!--.container-->

<script>
$('#coffee').selectpicker();

$('#submit').on("click", function(e) {
    e.preventDefault();

    $('#coffee').selectpicker('refresh');

    $.ajax({
    type: "POST",
    url: `addCoffee.php?coffee=${coffee}`,

    success: function (response) {
        alert("Successfully submitted Coffee for review.");
    }
    });

})
</script>

1 个答案:

答案 0 :(得分:0)

尝试这个

=ArrayFormula(if(A2:A="","",100-(row(A2:A)-row())*J5))