반응형
<body>
<input type="checkbox" id="myCheckBox">
<label for="myCheckBox">subscribe</label><br>
<input type="radio" id="visaBtn" name="card">
<label for="visaBtn">Visa</label><br>
<input type="radio" id="masterCardBtn" name="card">
<label for="masterCardBtn">masterCard</label><br>
<button id="mySubmit" type="submit">submit</button>
<p id="subResult"></p>
<p id="paymentResult"></p>
<script src="index.js"></script>
const myCheckBox = document.getElementById("myCheckBox");
const visaBtn = document.getElementById("visaBtn");
const masterCardBtn = document.getElementById("masterCardBtn");
const mySubmit = document.getElementById("mySubmit");
const subResult = document.getElementById("subResult");
const paymentResult = document.getElementById("paymentResult");
mySubmit.onclick = function(){
if(myCheckBox.checked){
subResult.textContent = "You are subscribed";
if(visaBtn.checked){
paymentResult.textContent="You are paying with Visa";
}
else if(masterCardBtn.checked){
paymentResult.textContent="You are paying with masterCard";
}
else {
paymentResult.textContent="You have to select payment type";
}
}
else {
subResult.textContent = "You are NOT subscribed";
paymentResult.textContent="";
}
}
myCheckBox.checked : myCheckBox가 체크됐다면,,
반응형
'FrontEND > JavaScript' 카테고리의 다른 글
try, catch, finally (0) | 2024.03.08 |
---|---|
string 메소드 (0) | 2024.01.24 |
사용자가 입력한 값에 따라 출력하기 IF문사용 (0) | 2024.01.24 |
1~45숫자중에서 로또번호 만들기 (0) | 2024.01.24 |
getElementById,onclick 함수 사용법 (0) | 2024.01.23 |