jQuery: Select Multiple Dropdown Items

Back in 2006 I posted a simple piece of Javascript code that would let you select multiple items from a dropdown (or multiselect box) to a textarea. This code has been very popular and people liked it as I can see from different forums being linked to this post.

Here is the same code, but it uses jQuery to do the job. Smaller piece of code than what I’d before. HTML piece remains same and here is the example:

 
 

HTML Code:

<form method=POST name='testing'>  
  <select name='testsel' multiple id='testsel'>  
    <option value="one">one</option>
    <option value="two">two</option>
    <option value="three">three</option>  
  </select>  
  <textarea id="txtEditions"></textarea>
</form>

jQuery Code:

<script type="text/javascript">
var glue = '+';
try {
	$('#testsel').change(function() {
		$('#txtEditions').val(($('#testsel').val()).join(glue));
	});
} catch(e) {
	console.log(e);
}
</script>

One thought on “jQuery: Select Multiple Dropdown Items”

Leave a Reply