jquery - How do I populate values for multiple chosen plugin? -
i using jquery plugin (http://harvesthq.github.io/chosen/) , having trouble populating selected values textbox.
based on options page, says $('.my_select_box').trigger('chosen:updated');
however have multiple select boxes, say
<select id="select1" class="chzn-select" name="select1" data-placeholder="choose employee..." multiple="true" style="width: 350px; display: none;"></select> <select id="select2" class="chzn-select" name="select2" data-placeholder="choose employee..." multiple="true" style="width: 350px; display: none;"></select> <select id="select3" class="chzn-select" name="select3" data-placeholder="choose employee..." multiple="true" style="width: 350px; display: none;"></select>
and in jquery script have
$('.chzn-select', this).chosen(); // use prepopulate?
but if had selected values 3 select boxes, how populate values again?
i have function saves them database though:
$("#btnsave").click(function(){ var firstval= $("#select1").val(); var secondval= $("#select2").val(); var thirdval = $("#select3").val(); $.ajax({ type: "post", url: "mypost", data: { firstval:firstval, secondval :secondval, thirdval :thirdval; }, ....// do here? }); });
help appreciated. thanks!
desired output when page loaded:
i think need add selected attribute in option tag, see example here
in html:
<select id="ddlcarlist" multiple="multiple"> <option value="volvo">volvo</option> <option value="saab">saab</option> <option value="mercedes" selected="selected">mercedes</option> <option value="audi" selected="selected">audi</option> </select>
in javascript:
<script> jquery(document).ready(function() { jquery("#ddlcarlist").chosen(); }); </script>
Comments
Post a Comment