简体   繁体   中英

how to pass dropdown selected value to another dropdown

when i click button dropdown selected value pass to anotherone dropdown ..

Dropdown Selected value First one:

      <fieldset class="form-group">
           label class="form-label" for="exampleInputEmail1">Location <em style="color:red;font-size:18px;">*</em></label>
          <select class="select2-arrow" id="txtLocationID" name="txtLocationID"><option value="">--- Select Location ---</option>
    <option value="1">EGL 4 club house</option>
    </select>
   </fieldset>

In above dropdown selected value passed to second one dropdown

 <fieldset class="form-group">
    <label class="form-label" for="exampleInputEmail1">Location <em style="color:red;font-size:18px;">*</em></label>
   @Html.DropDownList("txtLocationID", null, "--- Select Location ---", new { @class = "select2-arrow" })
  </fieldset>

Button click: EGL 4 club house Value pass to second dropdown

$("#VenueBooking").click(function (e) {

        var locationID = jQuery('[id$=LocationID]').val();

    });
var locationID = jQuery('[id$=LocationID]').val();
jQuery('[id$=txtLocationID]').val(locationID);

Simply set select value to next dropdown with val()

$("#VenueBooking").click(function (e) {
   $('[id$=txtLocationID]').val($('[id$=LocationID]').val());
});

I'm not getting what exactly do you want to achieve but as far as I've understood, do you want to select one value in one dropdown and want to select that value in second dropdown? You could achieve it in JQuery by doing this approach:

$("#firstdropdown").change(function (e) {
$("#seconddropdown").val($("#firstdropdown").val());

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM