How to Select Multi Select Picklist Value using Javascript</span>
Example to get the multi select picklist value using javascript
Example :1
<script language=”JavaScript”>
function getSelectedCountryValues() {
var dropDown = document.getElementById(‘countryValue’), countryValue = [], i;
for (i = 0; i < dropDown.options.length ; i += 1) {
if (dropDown.options[i].selected) {
//countryValue.push( dropDown.options[i].value); //If you only need values
countryValue.push({ Name: dropDown.options[i].text, Value: dropDown.options[i].value });
}
}
console.log(countryValue);
alert(‘countryValue’+ countryValue);
return false;
}
</script>
<form><label>Multi Select dropdown </label>
<select id=”countryValue” multiple=”multiple”>
<option value=”0″>Australia</option>
<option value=”0″>India</option>
<option value=”1″>United States</option>
<option value=”2″>United Kingdom</option>
<option value=”3″>China</option>
<option value=”4″>Bangladesh</option>
</select>
<input type=”submit” value=”Submit” /></form>
Example 2:
<select multiple=”multiple” name=”mySel”>
<option value=”val1″>option 1</option>
<option value=”val2″>option 2</option>
<option value=”val3″>option 3</option>
<option value=”val4″>option 4</option>
</select>
<button type=”button”>Show selected values</button>
</script><script type=”text/javascript”>
function showSelectsd(){
var selO = document.getElementsByName(‘mySel’)[0];
var selValues = [];
for(i=0; i < selO.length; i++){
if(selO.options[i].selected){
selValues.push(selO.options[i].value);
}
}
}
</script>