How can i get the selected values from the chosen Multi-select Box?
问题:
回答1:
Like from any regular input/select/etc...:
$("form.my-form .chosen-select").val()
回答2:
$("#select-id").chosen().val()
回答3:
This worked for me
$(".chzn-select").chosen({ disable_search_threshold: 10 }).change(function(event){ if(event.target == this){ alert($(this).val()); } });
回答4:
$("#select-id").chosen().val()
this is the right answer, I tried, and the value passed is the values separated by ","
回答5:
If anyone wants to get only the selected value on click to an option, he can do the follow:
$('.chosen-select').on('change', function(evt, params) { var selectedValue = params.selected; console.log(selectedValue); });
回答6:
As of 2016, you can do this more simply than in any of the answers already given:
$('#myChosenBox').val();
where "myChosenBox" is the id of the original select input. Or, in the change event:
$('#myChosenBox').on('change', function(e, params) { alert(e.target.value); // OR alert(this.value); // OR alert(params.selected); // also in Panagiotis Kousaris' answer }
In the Chosen doc, in the section near the bottom of the page on triggering events, it says "Chosen triggers a number of standard and custom events on the original select field." One of those standard events is the change event, so you can use it in the same way as you would with a standard select input. You don't have to mess around with using Chosen's applied classes as selectors if you don't want to. (For the change
event, that is. Other events are often a different matter.)
回答7:
if you want to get text of a selected option (chosen get display selected value)
$("#select-id").chosen().find("option:selected" ).text();