0

<html>
<head>
<title>Multi-select</title>
<link rel="stylesheet" type="text/css" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="bower_components/bootstrap-multiselect/dist/css/bootstrap-multiselect.css">
<script type="text/javascript" src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="bower_components/bootstrap-multiselect/dist/js/bootstrap-multiselect.js"></script>
</head>
<body>
<select id="example" multiple="multiple">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<script>
  $('#example').multiselect({
    buttonClass: "btn btn-default",
    buttonWidth: "140px",
  });
</script>
</body>
</html>

this is my code...i have to print selected values from dropdownlist...how can i use jquery...if i select 1,2,3 options it will print that values

Sai Rajesh
  • 1,882
  • 5
  • 22
  • 41
  • 3
    Possible duplicate of [How to get the text of the selected option of a select using jquery?](http://stackoverflow.com/questions/1391019/how-to-get-the-text-of-the-selected-option-of-a-select-using-jquery) – Atula May 03 '16 at 07:18

2 Answers2

1

You can use .val() along with select element selector:

When the first element in the collection is a select-multiple (i.e., a select element with the multiple attribute set), it returns an array containing the value of each selected option, or null if no options are selected.

$('#example').val(); 

You can convert this array to CSV using .join().

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0
$( "#myselect option:selected" ).text();
John
  • 4,711
  • 9
  • 51
  • 101