2
I’m trying to search and change the values of a checkbox using Javascript. The intention is, when the JS function is called, to check if the checkbox is set. If not, seven-a as checked, and vice versa. However, when trying to read the checkbox state the following error is shown:"Cannot read Property 'checked' of null"
My last attempt so far was as follows::
<label for="letrasMinusculas">
<img src="images/checked.png" id="imgLetrasMinusculas" onclick="changeIcon(letrasMinusculas)">
</label>
<input id="letrasMinusculas" class="boxOculto" name="letrasMinusculas" type="checkbox" checked>
And in Javascript:
function changeIcon(id){
var status = document.getElementById(id);
if (status.checked){
alert("Verdadeiro");
}
else{alert("Falso");}
}
Note: The checkbox receives the class "boxOculto" (display: None) because I prefer to use a label with image for the user to click for customization.
Tried to pass ID as string? like this
onclick="changeIcon('letrasMinusculas')"
?– Franchesco
That was the mistake. Thank you very much for your help.
– Matheus Godoi