TOP /JavaScript | チェックボックスのチェック制限 |
---|
<script language="JavaScript"><!-- chmax=3; //最大チェック数 //-------------------------- function check(chobj){ if(!chobj.checked)return; chname1=chobj.name; chint=0; elementleng=document.forms[0].elements[chname1].length; for(i=0;i<elementleng;i++){ if(document.forms[0].elements[chname1][i].checked){ chint++; if(chint>chmax){chobj.checked=false;break;} } } }/*himajin.moo.jp*/ // --></script> <form> 1項目3箇所以上選択できません。<br> <table border=1><tr> <td>項目T</td><td> <input name="No1"type="checkbox"value=""onclick="check(this)">No1-1 <input name="No1"type="checkbox"value=""onclick="check(this)">No1-2 <input name="No1"type="checkbox"value=""onclick="check(this)">No1-3 <input name="No1"type="checkbox"value=""onclick="check(this)">No1-4 <input name="No1"type="checkbox"value=""onclick="check(this)">No1-5 <input name="No1"type="checkbox"value=""onclick="check(this)">No1-6 </td></tr><tr> <td>項目U</td><td> <input name="No2"type="checkbox"value=""onclick="check(this)">No2-1 <input name="No2"type="checkbox"value=""onclick="check(this)">No2-2 <input name="No2"type="checkbox"value=""onclick="check(this)">No2-3 <input name="No2"type="checkbox"value=""onclick="check(this)">No2-4 <input name="No2"type="checkbox"value=""onclick="check(this)">No2-5 <input name="No2"type="checkbox"value=""onclick="check(this)">No2-6 </td></tr></table> </form>