0

Good day, i have a dropdown that when is selected it must populate the value to the input using data-idbecause i'm already using the idfor something else. 请注意,数据填充到下拉列表select中。

这是inputselect

<input type="text" id="@appConfig.Id" data-id="WarehouseInput" data-itemType="int" name="@appConfig.Name" class="form-control" required />

 <select type="text" value="SelectWarehouse" name="@appConfig.Name" id="SelectWarehouse" data-itemType="int" class="selectpicker show-tick  form-control" data-live-search="true"></select>

When the when the dropdown is selected it need to populate the value oninput

$(function () {
$("#SelectWarehouse").change(function () {

    var selectedText = $(this).find("option:selected").text();
    var selectedValue = $(this).val();
    $(this).attr("data-id", "WarehouseInput");
   // var inputid = document.getElementById("WarehouseInput");
    //alert("Selected Text: " + selectedText + " Value: " + selectedValue);
});});
4

1 回答 1

1
$(function () {
   $("#SelectWarehouse").change(function (e) {
       $('[data-id="WarehouseInput"]').val(e.target.value);
  });
});
于 2018-06-14T08:03:44.887 回答