02. november 2003 - 15:29
Der er
4 kommentarer og 1 løsning
Max antal checked checkboxe.
Hvis jeg har følgende : <form action=index.php method=post> <input type=checkbox name=1 value=1> 1<br> <input type=checkbox name=2 value=2> 2<br> <input type=checkbox name=3 value=3> 3<br> <input type=checkbox name=4 value=4> 4<br> <input type=checkbox name=5 value=5> 5<br> <input type=checkbox name=6 value=6> 6<br> <input type=checkbox name=7 value=7> 7<br> <input type=checkbox name=8 value=8> 8<br> <input type=checkbox name=9 value=9> 9<br> <input type=checkbox name=10 value=10> 10<br> <input type=checkbox name=11 value=11> 11<br> <input type=checkbox name=12 value=12> 12<br> <input type=checkbox name=13 value=13> 13<br> <input type=checkbox name=14 value=14> 14<br> <input type=checkbox name=15 value=15> 15<br> <input type=checkbox name=16 value=16> 16<br> <input type=submit value=Spil> </form> ...altså 16 muligheder for "check" - og vil begrænse antallet af "check" til f.eks. 10 - hvordan gør jeg det???
Annonceindlæg fra Admin By Request
02. november 2003 - 15:52
#3
<script type="text/javascript"> function init(){ elm = document.forms[0].elements for (i=0;i<elm.length;i++){ if (elm[i].type=="checkbox"){ elm[i].onclick=new Function("check(this);"); } } } function check(last){ elm = document.forms[0].elements chk = 0; for (i=0;i<elm.length;i++){ if (elm[i].type=="checkbox" && elm[i].checked){ chk++; } } if (chk>10){ alert('max 10 kan vælges'); last.checked=false; } } </script> <body onload="init();"> <form action=index.php method=post> <input type=checkbox name=1 value=1> 1<br> <input type=checkbox name=2 value=2> 2<br> <input type=checkbox name=3 value=3> 3<br> <input type=checkbox name=4 value=4> 4<br> <input type=checkbox name=5 value=5> 5<br> <input type=checkbox name=6 value=6> 6<br> <input type=checkbox name=7 value=7> 7<br> <input type=checkbox name=8 value=8> 8<br> <input type=checkbox name=9 value=9> 9<br> <input type=checkbox name=10 value=10> 10<br> <input type=checkbox name=11 value=11> 11<br> <input type=checkbox name=12 value=12> 12<br> <input type=checkbox name=13 value=13> 13<br> <input type=checkbox name=14 value=14> 14<br> <input type=checkbox name=15 value=15> 15<br> <input type=checkbox name=16 value=16> 16<br> <input type=submit value=Spil> </form> </body>