checkboxの全選択とキャンセルの例
1861 ワード
<script language="JavaScript" type="text/javascript">
function $(objName) {
return document.getElementById(objName);
}
function selectItems(checkboxName) {
var isNeedCheck = false;
for(var i = 0; i < 10; i++) {
var obj = $(checkboxName + (i + 1));
if (obj) {
if (!obj.checked) {
isNeedCheck = true;
break;
}
} else {
break;
}
}
for(var i = 0; i < 10; i++) {
var obj = $(checkboxName + (i + 1));
if (obj) {
obj.checked = isNeedCheck;
}
}
}
</script>
<table>
<tr>
<td>
<input type="button" name="allSelect" onclick=selectItems('resultCheckbox'); value=" " >
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="resultCheckbox1">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="resultCheckbox2">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="resultCheckbox3">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="resultCheckbox4">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="resultCheckbox5">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="resultCheckbox6">
</td>
</tr>
</table>