|
Subject:
|
How to restrict the maximum number of possible sel
|
|
Posted By:
|
lily611
|
Post Date:
|
11/1/2004 1:39:45 AM
|
Hi,
How to restrict the maximum number of possible selections in a multiple list box or drop-down list in ASP or javascript. In my application i have to restrict the maximum selection must be greater than 3 from the dropdown list.
Regards Lily
|
|
Reply By:
|
rajanikrishna
|
Reply Date:
|
11/1/2004 5:06:24 AM
|
I think there is no specific property to limit selection.
You can do in javascript.
Loop thru all items in the select control and increment the counter for each one selected. Test the couter with your reqd value and display an alert.
------------ Rajani
|
|
Reply By:
|
lily611
|
Reply Date:
|
11/1/2004 6:29:32 AM
|
How to write the script, can u give the code, plz?
|
|
Reply By:
|
rajanikrishna
|
Reply Date:
|
11/1/2004 8:25:11 PM
|
Hi,
<form name="frm1"> <select name="sel1" id="sel1" multiple> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> <option value="5">Five</option> </select>
<input type="button" value="Check" onclick="chkData()"> </form>
<script language="javascript"> function chkData(){ var test=0; for(i=0;i<parseInt(frm1.sel1.options.length);i++){ if(frm1.sel1.options(i).selected){ test++; } } if(test>3){ alert("You can select maximum of 3 options only"); return false; } } </script>
---------- Rajani
|
|
Reply By:
|
lily611
|
Reply Date:
|
11/2/2004 12:11:08 AM
|
Thanks a lot Rajani.
---------------------------------------------------------------- Lily
|