- 2005. 9. 7. 22:45 -
<HTML>
<HEAD>
<TITLE>CHECKBOX</TITLE>
<script>
function check(){
cbox = input_form.chk;
if(cbox.length) { // 여러 개일 경우
for(var i = 0; i<cbox.length;i++) {
cbox[i].checked=input_form.all.checked;
}
} else { // 한 개일 경우
cbox.checked=input_form.all.checked;
}
}
</script>
</HEAD>
<BODY>
<form name="input_form">
<input type="checkbox" name="all" onclick="check();">check all<br>
<input type="checkbox" name="chk" value="01" color="white">TEST1<br></font>
<input type="checkbox" name="chk" value="02" color="white">TEST2<br></font>
<input type="checkbox" name="chk" value="03" color="white">TEST3<br></font>
<input type="checkbox" name="chk" value="04" color="white">TEST4<br></font>
</form>
</body>
</html>
--------------------------------------------------------
체크여부 확인
for(var i = 0; i<cbox.length;i++) {
if(cbox[i].checked==true){
alert(cbox[i].value);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
ex2)
<html>
<head>
<title>test</title>
<script language="JavaScript">
function chkMsg()
{
var str=""
n=frm.elements.length
for(i=0;i<n;i++)
{
if(frm.elements[i].checked==true)
str+=frm.elements[i].value + ", "
}
alert("" + str + "")
}
</script>
</head>
<body>
<form name=frm>
<input type="text" name="aa">
<input type="checkbox" name="animal" value="고양이">고양이
<input type="checkbox" name="animal" value="개">개
<input type="checkbox" name="animal" value="앵무새">앵무새
<input type="checkbox" name="animal" value="나비">나비
<input type="image" src="images/ani_button.gif" onclick="chkMsg()">
</form>
</body>
</html>