Question : selecting values in a select box multiple

i have one select box and want to select 5 values @ a time, if values exceed more than 5, it show popup and error! only 5 allowed! please guide

Answer : selecting values in a select box multiple

My version
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
<script>
var maxSel = 3;
var selected =[];
window.onload=function() {
  saveSel(document.getElementById('sel')); // initialise
}
function saveSel(sel) {
  for (var i=0;i<sel.options.length;i++) {
    selected[i]=(sel.options[i].selected); 
  }
}
function resetSel(sel) {
  for (var i=0;i<sel.options.length;i++) {
    sel.options[i].selected = selected[i]; 
  }
}
function test(sel) {
  for (var i=0,newCnt=0;i<selected.length;i++) {
    newCnt+= (sel.options[i].selected)?1:0;
  }
  if (newCnt>maxSel) {
    alert('Sorry, you can only select a maximum of '+maxSel);
    resetSel(sel);
  }
  else saveSel(sel); // store the new 
}

</script>
<select id='sel' multiple onChange="test(this)">
<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>
Random Solutions  
 
programming4us programming4us