Q:

how to get multiple selected values and items from listbox using javascript

<!DOCTYPE html>
<html>
<script>
function getValue()
{
  var x=document.getElementById("sel");
  for (var i = 0; i < x.options.length; i++) {
     if(x.options[i].selected ==true){
          alert(x.options[i].selected);
      }
  }
}
</script>
</head>
<body>
<select multiple="multiple" id="sel">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>
<input type="button" value="Get Value" onclick="getValue()"/>
</body>
</html>

This is my code. how do i get all the selected values from listbox using javascript.The above code showing show true for all selected value.

A:

Replace
  if(x.options[i].selected ==true){
      alert(x.options[i].selected);
  }

with
  if(x.options[i].selected){
      alert(x.options[i].value);
  }

A:

I suggest that you do it using jQuery like this:
var selected = $('#sel option:selected');

If you prefer not to use jQuery then disregard this answer and refer to the other ones.

A:

use selectedOptions 
for (var i = 0; i < x.selectedOptions.length; i++) {
    alert(x.selectedOptions[i].value);
}

