Checkbox value not changing from false to true when checked
checkbox, forms, javascript
Solution
The problem is in the second part of the first if statement where you compare
document.getElementById("c_ierrors").checked!="true"
Comparing a boolean to a string gives you the wrong result. You can check this in your JavaScript console with,
bool_val = true
bool_val == "true" # returns false
You either need to compare to `true` or just use it as a boolean value. E.g.
document.getElementById("c_ierrors").checked != true
or
!document.getElementById("c_ierrors").checked
Problem
This javascript function finds the errors in a form and lists them. If there are errors, it creates an error override checkbox to allow submission even with errors. At present the code does not recognize when the checkbox is checked. Apparently the first if statement is always found to be true. Ideas? ``` function check1() { // c_ierrors is the id of the input tag inserted below within the c_erros div if( document.getElementById("c_ierrors")==null || document.getElementById("c_ierrors").checked!="true" ) { //if javascript generated form error overide checkbox does not exist or exists but is not true then list errors and don't submit the form //code to generate divs listing errors // if(error=="") { //submit form return true; } else { error += "<div id=\"c_erow\"><input type=\"checkbox\" id=\"c_ierrors\" name=\"override\" value=\"y\" >Override Errors</div>" //add checkbox to submit form despite errors document.getElementById("c_errors").innerHTML=error; alert (document.forms["cform"]["override"].checked); return false; //stay on page don't submit form } } else { //if override checkbox (exists) and is true return true; } } ```