This is small problem I am facing. I am printing a checkbox list in which they are checked if the JSON value coming inside them is true and unchecked if JSON value is false.
So if the checkbox is checked the line of html is
<input id="to_be_shown_individually" type="checkbox" ${(this.to_be_shown_individually && 'checked')} value=> <br>
Now , i have given option to user to check and uncheck chekbox . So when they uncheck the checkbox its value remains true always.
See this image in first as chekbox are checked so i get true, but in second attempt when i uncheck them i still get true .
so when i use
documen.getElementByID("to_be_shown_individually").value;
It always says true whther user have unchecked the checkbox
3
Answers
The
value
of a checkbox is always available. To determine if it’s checked or not you need to use thechecked
property:Instead of
document.getElementByID("to_be_shown_individually").value;
Look for
document.getElementByID("to_be_shown_individually").checked;
this will give you a true or false response based on if the checkbox is checked
html
javascript code