javascript - Get the value that was just selected from a jQuery Chosen multiple select element -
i using jquery chosen convert select multiple select. when choose second item, gives me both selected items when $(this).val()
.
i want value item select @ moment.
following code.
$("#languageid").chosen().on("change",function() { alert($(this).val()); });
html:
<select id="languageid" multiple > <option value="hindi">hindi</option> <option value="english">english</option> </select>
according the documentation:
chosen triggers standard dom event whenever selection made (it sends
selected
ordeselected
parameter tells option changed).
therefore can access selected
/deselected
property on params
object passed in change
event callback. in other words, params.selected
/params.deselected
value of option
element selected/deselected.
$("#languageid").chosen().on("change", function(event, params) { var value = $(this).val(); var changedvalue = params.selected || params.deselected; // ... });
addressing comment below, check property on params
object in order determine whether option selected/deselected:
$("#languageid").chosen().on("change", function(event, params) { if (params.selected) { console.log('the option: ' + params.selected + ' selected.'); } if (params.deselected) { console.log('the option: ' + params.deselected + ' deselected.'); } });
Comments
Post a Comment