<html>
<head>
<title> New Document </title>
<script language="javascript">
function fnDataSubmit(){
   var frm = document.form;
   var cnt = 0;
   var choiceSport = "";
 
   for(var i=0; i<frm.elements("sport").length; i++){
     if(frm.elements("sport")[i].checked == true){
        choiceSport += frm.elements("sport")[i].value + "&&";
        cnt++;
     }
   }

 //위의 코드는 아래와 같이 사용해도 됨
 /*
   for(var i=0; i<frm.sport.length; i++){
      if(frm.sport[i].checked == true){
         choiceSport += frm.sport[i].value + "&&";
         cnt++;
      }
   }
 */


 alert(choiceSport);
 //alert(cnt);
}
</script>
</head>

<body>
<form name="form" method="post">
 <input type="checkbox" name="sport" value="soccer">축구<br>
 <input type="checkbox" name="sport" value="baseball">야구<br>
 <input type="checkbox" name="sport" value="basketball">농구<br>
 <input type="checkbox" name="sport" value="golf">골프<br>
 <input type="checkbox" name="sport" value="etc">기타<br>

 <input type="button" name="trans" value="submit" onClick="fnDataSubmit();">
</form>
</body>
</html>

이런식으로 처리하면 되니
간단하게 응용도 가능...

+ Recent posts