vendredi 21 septembre 2018

i can't understand why my code doesn't work can someone please check it out? I am very new (JavaScript)

this is the script

<script>
var a,b,c;
a = document.getElementById("myCheck1");
b = document.getElementById("myCheck2");
c = document.getElementById("myCheck3");

this function works only if the other one is a comment

function check() { 
if (a.checked == true)
document.getElementById("a").innerHTML="a true";
else
document.getElementById("a").innerHTML="a false";

if (b.checked == true)
document.getElementById("b").innerHTML="b true";
else
document.getElementById("b").innerHTML="b false";

if (c.checked == true)
document.getElementById("c").innerHTML="c true";
else
document.getElementById("c").innerHTML="c false";
}

this function doesnt work and make the other one not to work

function clickOnB() {
if (a.checked == true || c.checked == true)
a.checked = false;
c.checked = false;
else
b.checked = true;
}
</script>

this is the body

Checkbox1: <input type="checkbox" id="myCheck1" value="a"/>
Checkbox2: <input type="checkbox" id="myCheck2" onclick="clickOnB() " 
value="b"/>
Checkbox3: <input type="checkbox" id="myCheck3" value="c"/>
<p id="a"></p>
<p id="b"></p>
<p id="c"></p>
<button type="button" onclick="check()" />




Aucun commentaire:

Enregistrer un commentaire