-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_multiple_checkbox.html
More file actions
38 lines (35 loc) · 1.29 KB
/
read_multiple_checkbox.html
File metadata and controls
38 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
<title>DOM Basic</title>
</head>
<body>
<input type="checkbox" class="check" value = 100>
<label>100원</label> <br>
<input type="checkbox" class="check" value = 300>
<label>300원</label> <br>
<input type="checkbox" class="check" value = 500>
<label>500원</label> <br>
<input type="checkbox" class="check" value = 1000>
<label>1000원</label> <br>
<input type="checkbox" class="check" value = 5000>
<label>5000원</label> <br>
<input type="checkbox" class="check" value = 10000>
<label>10000원</label> <br>
<input type="button" id="myButton" value="계산" onclick="getCheckbox()"><br>
<script>
function getCheckbox() {
let checkboxes = document.getElementsByClassName("check");
let sum = 0;
for(let i=0; i<checkboxes.length;i++){
if(checkboxes[i].checked) {
sum += parseInt(checkboxes[i].value);
alert('체크하신 금액은 ' + checkboxes[i].value + ' 원 입니다.');
}
}
alert('총 금액은 ' + sum + ' 원 입니다.')
}
</script>
</body>
</html>
//각각 가격을 출력하는 코드를 추가하였고, 더 많은 금액을 선택할 수 있도록 바꿈