mercredi 26 juillet 2023

why JavaScript code i wrote is not working

Its my code in html :

subscribe
<label for="visaBtn">Visa</label>
<input type="radio" name ="card" id="visaBtn">
<label for="mastercardBtn">MasterCard</label>
<input type="radio" name="card" id="mastercardBtn">
<label for="paypalBtn">Paypal</label>
<input type="radio" name="card" id="paypalBtn"><br>
<button id="myCheckBox">submit</button>
<script src="index.js"></script>

body>

Then I wrote this function on JavaScript but when I am trying it on the browser it isn't working.

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

const myCheckBox =document.getElementById("myCheckBox");
const visaBtn = 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(visaBtn.checked){
    console.log("You are paying with a Visa!");
 }
 else if(mastercardBtn.checked){
    console.log("You are paying with a Mastercard!");
 }
 else if(paypalBtn.checked){
    console.log("You are paying with a Paypal!");
 }
 else{
    console.log("You must select a payment type!");
 }

I want to know what's wrong with my code?




Aucun commentaire:

Enregistrer un commentaire