<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>물품을 선택하면 금액 자동계산</title>
<script>
function sumCalc(obj){
let sum = document.querySelector("#sum");
if(obj.checked){
sum.value = parseInt(sum.value) + parseInt(obj.value);
}else{
sum.value = parseInt(sum.value) - parseInt(obj.value);
}
}
</script>
</head>
<body>
<h1>물품을 선택하면 금액이 자동계산됩니다.</h1>
<hr>
<input type="checkbox" name="hat" id="hat" value="10000" onclick="sumCalc(this)">
<label for="hat">모자 1만원</label>
<input type="checkbox" name="bag" id="bag" value="80000" onclick="sumCalc(this)">
<label for="bag">가방 8만원</label>
<input type="checkbox" name="shoes" id="shoes" value="30000" onclick="sumCalc(this)">
<label for="shoes">구두 3만원</label>
<label for="sum">지불하실금액</label>
<input type="number" name="sum" id="sum" readonly value="0">
</body>
</html>


