srikotesh
asked on
how to get limited multiselect values from the list box
Hi Experts,
Below is the list box having list of values
i can do multi select from the list box
i have to show an alert if the user choosen more than 5 values from the list
alert-->please choose only 5 values.
finally i have to see the list of selected items in an var called result
example
if user choose vals as 45,123,456,
i have to assign those values to result var with comma separted as shown in above lline
Below is the list box having list of values
i can do multi select from the list box
i have to show an alert if the user choosen more than 5 values from the list
alert-->please choose only 5 values.
finally i have to see the list of selected items in an var called result
example
if user choose vals as 45,123,456,
i have to assign those values to result var with comma separted as shown in above lline
<!DOCTYPE html>
<html>
<script>
function getValue()
{
var x=document.getElementById("sel");
result = '';
alert("length is"+x.options.length);
for (var i = 0; i < x.options.length; i++) {
if(x.options[i].selected){
alert(x.options[i].value);
result = result +"," +x.options[i].value;
//selcustid = selcustid + ",'" + document.adcrptform.custid.options[i].value + "'";
}
}
alert("result is "+result);
}
</script>
</head>
<body>
<select multiple="multiple" id="sel">
<option value="123">123</option>
<option value="456">456</option>
<option value="789">789</option>
<option value="234">234</option>
<option value="45">45</option>
<option value="765">765</option>
<option value="435">435</option>
<option value="321">321</option>
<option value="123">123</option>
</select>
<input type="button" value="Get Value" onclick="getValue()"/>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER