samedi 7 août 2021

How can I ensure that an if else statement works only if the exact condition is true in javascript?

I have an if/else statement that returns an image if the chicken checkbox is checked, however, if you check the chicken checkbox and another one it still displays the image, how can I set the statement to only display the image only if the chicken checkbox is checked?

The code is as follows:

if (chicken.checked == true) {
  document.getElementById("image").style.visibility = "visible";
} else {  
  return document.getElementById("error").innerHTML = "*Please mark any of checkbox";  
} 

Aucun commentaire:

Enregistrer un commentaire