0
Display text with a checkbox
I would like to display some text (help) when the checkbox (?) is checked: but I can't do it ... Why? This is my code: - - - HTML <input type="checkbox" id="what" name="help" value="yes" onclick="aide()"/> <label for="what"> ? </label> <div id="info">Some text to display for helping</div> - - - JAVASCRIPT function aide() { let what=document.getElementById("what"); let info=document.getElementById("info"); if (what.cheked) { info.style.display="inherit"; } else { info.style.display="none"; }; } - - - Thank for helping
3 Antworten
+ 2
You would just do the same thing. If you mean how you would check which box is checked, that's a little different, because with checkboxes, all of them can be checked, so you have to validate every case.
if (a.checked && b.checked)
else if (a.checked)
else if (b.checked)
else // none are checked
+ 2
cheked needs to be spelled properly. Add a 'c': what.checked
This is why using a text editor with intellisense or autocompletion is really helpful.
0
I found the answer:
- - - HTML
<input type="checkbox" id="aide" onclick="aide()">
<label for="aide">?</label>
<div id="info">Some text</div>
- - -JAVASCRIPT
function aide() {
var aide = document.getElementById("aide");
var info = document.getElementById("info");
if (aide.checked == true){
info.style.display = "block";
} else {
info.style.display = "none";
}
}
But... If i have more that one check box, how i can do it? With the class??