Reputation: 1607
I would like to allow multiple selection of items so that the #par
displays all 3 values selected with a shift. This post leads me to believe such functionality is not built in with jQuery, and needs a workaround, although it is from 3 years ago. I use jsFiddle and 1.9.1 jQuery.
<select id="select" multiple>
<option value="item1">item1</option>
<option value="item2">item2</option>
<option value="item3">item3</option>
</select>
<br />
<p id="par"></p>
$('#select').change(function(){
$('#select option:selected').each(function(){
$("#par").text($(this).text() + ", ");
});
});
Upvotes: 0
Views: 389
Reputation: 337590
You can get a comma separated list of the values chosen in a multiple select by using val()
- the same as you would any other form element. Try this:
$('#select').change(function() {
$("#par").text($(this).val());
});
Upvotes: 2