선택장애

자바스크립트 - 체크박스값 받아서 알람띄우기(alert) 본문

자바스크립트

자바스크립트 - 체크박스값 받아서 알람띄우기(alert)

yes or yes 2017. 8. 14. 15:11
반응형

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>

<script language = "javascript">

function disp(){
 
 var msg = "다음 여행지를 선택화셨습니다.\n";
 var checkBoxes = document.getElementsByName("country");
 
 for(var i=0; i<checkBoxes.length; i++){
  if(checkBoxes[i].checked){
   msg += "-" + checkBoxes[i].value + "\n";
   
  }
  
 }
 
 alert(msg);
 
}

</script>

</head>
<body>

<h1> 지금 가장 가고 싶은 곳은? </h1>

<input type = "checkbox" name = "country" id="japan">일본
<input type = "checkbox" name = "country" id="america">미국
<input type = "checkbox" name = "country" id="canada">캐나다
<input type = "checkbox" name = "country" id="house">집

<input type = "button" value="답변하기" onclick="disp()">
</body>
</html>

반응형