본문 바로가기

개발하자/자바스크립트

document.f.box[i].checked 체크한값불러오기

<html>
<head>
<style type="text/css">
</style>
<script>
window.onload=function(){
document.f.b.onclick=function(){
var buffer=[];
var len=document.f.box.length;
for(var i=0; i<len; i++){
if(document.f.box[i].checked)
buffer.push(document.f.box[i].value);
}
document.f.txt.value=buffer.join(",");
}
}
</script>
</head>
<body>
<form name="f">
<input type="checkbox" name="box" value="aa">aa
<input type="checkbox" name="box" checked value="bb">bb
<input type="checkbox" name="box" value="cc">cc
<input type="checkbox" name="box" value="dd">dd
<input type="button" value="선택된것은?" name="b">
<input type="text" name="txt">
</form>
</body>
</html>