Checked property


Html

<label for="myCheckBox">Subscribe </label>
<input type="checkbox" id="myCheckBox"> </input>
<button id="myButton">Submit</button>

Javascript

document.getElementById("myButton").onclick = function(){

if(document.getElementById("myCheckBox").checked){
console.log("you are subscribed!")
} else {
console.log("You are not subscribed!")
}

Monitor result ⬇️





result: same as above, only change variable


document.getElementById("myButton").onclick = function(){

const myCheckBox = document.getElementById("myCheckBox")
if(myCheckBox.checked){
console.log("you are subscribed!")
} else {
console.log("You are not subscribed!")
}

Html

<label for="myCheckBox">Subscribe </label>
<input type="checkbox" id="myCheckBox"> </input>

<label for="visaBtn">Visa</label>
<input type="radio" name="card" id="visaBtn">

<label for="mastercardBtn">Mastercar</label>
<input type="radio" name="card" id="mastercardBtn">

<label for="paypalBtn">PayPal</label>
<input type="radio" name="card" id="paypalBtn">

<button id="button">Submit</button>

Javascript

document.getElementById("button").onclick = function(){

const myCheckBox = document.getElementById("myCheckBox")
const vistaBtn = document.getElementById("visaBtn")
const mastercardBtn = document.getElementById("mastercardBtn")
const paypalBtn = document.getElementById("paypalBtn")

if(myCheckBox.checked){
console.log("you are subscribed!")
} else {
console.log("You are not subscribed!")
}
if(vistaBtn.checked){
console.log("You are paying with VISA")
}
else if(mastercardBtn.checked){
console.log("You are paying with MASTERCARD")
}
else if(paypalBtn.checked){
console.log("You are paying with PAYPAL")
}
else {
console.log("You must select a payment type!")
}
}

Monitor result ⬇️






(Flag "subscribe" also Up in this page)