Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Retrieve and reassigning multiselect value
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src=""></script>
<select id="the-list" multiple="multiple">
<option id="list-1" value="1">Hello World</option>
<option id="list-2" value="2">Foo</option>
<option id="list-3" value="3">Foobar</option>
<input type="text" id="list" readonly="readonly" value="" />
<button id="update">Update</button>
<button id="reset">Reset</button>
<script type="text/javascript">
jQuery(function($) {
$('#update').bind('click', function() {
var values = $('#the-list').val();
$('#reset').bind('click', function() {
var values = $('#list').val();
var value = values.split(',');
// you can actually set $('#id').val(['1', '2']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment