这个 javascript 函数在表单中查找错误并列出它们。如果有错误,它会创建一个错误覆盖复选框,即使有错误也允许提交。目前,当复选框被选中时,代码无法识别。显然,第一个 if 语句总是被发现为真。想法?
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;
}
}