javascript - setting Dropdown value by JQuery -
i have tried various method none of them seems working ..
my dropdown autocomplete , have used "select2" plugin that
this dropdown
@html.dropdownlist(model.deptprop, new selectlist(bmsa.ui.utility.utility.getalldepartments(model.countrycode), "value", "text", model.deptid), new { onchange = "getarrnds();" })
this jquery function
function loadmap(qstr){ alert($('select[name$=deptid]').val()); //this working fine, getting value dropdown // following methods not working var deptid=3; $("select[name$=deptid]").val(deptid); $("select[name$=deptid]").get(0).selectedindex = deptid; $('select[name$=deptid]').val(deptid).attr("selected", "selected"); $('select[name^="deptid"] option:selected').attr("selected",deptid); $('select[name^="deptid"] option[index="3"]').attr("selected","selected"); }
this parsed html
<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-deptid-container"><span class="select2-selection__rendered" id="select2-deptid-container" title="select below">select below</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span>
what can try more set value
you need trigger manually change event. taking https://select2.github.io/examples.html
$("select[name$=deptid]").val(deptid).trigger("change")
Comments
Post a Comment