我有 3 个字段用于输入 6 位代码以用于数据库(Quickbase)查询。每个字段都需要一个单独的警报/消息,让提交者知道代码是否无效。示例:“在字段 #1 中输入的数据无效”。我将下面的片段放在一起,它在一定程度上达到了结果。问题是当我只输入 1 个坏数据字段时,脚本可以工作,但是当我输入超过 1 个坏数据字段或将好数据与坏数据混合时,脚本不能正常工作......谢谢您的帮助。
这是字段
<input name="searchRecord" id="searchRecord1" type="text" size="8" maxlength="8" >
<input name="searchRecord" id="searchRecord2" type="text" size="8" maxlength="8">
<input name="searchRecord" id="searchRecord3" type="text" size="8" maxlength="8">
<input name="searchRecord" id="searchRecord4" type="text" size="8" maxlength="8">
<input name="searchRecord" id="searchRecord5" type="text" size="8" maxlength="8">
<input name="searchRecord" id="searchRecord6" type="text" size="8" maxlength="8">'
这是片段
var js = req.responseText;
eval(js);
if (qdb_numrows == 0); {
var x = true;
var msg = "Precert 1:\n";
if (document.getElementById('searchRecord1').value == qdb_numrows == 0) {
if (qdb_numrows == 0) //only receive focus if its the first error
document.getElementById('searchRecord1').focus();
//change border to red on error (i would use a class change here...
document.getElementById('searchRecord1').style.border = "solid 1px red";
alert(msg = "Error: Data entered for field #1 not required for procedure code Or procedure code is not valid!\n");
valid = false;
}
if (document.getElementById('searchRecord2').value == qdb_numrows == 0) {
if (qdb_numrows == 0) document.getElementById('searchRecord2').focus();
document.getElementById('searchRecord2').style.border = "solid 1px red";
alert(msg += "Error: Data entered for field #2 not required for procedure code Or procedure code is not valid!\n");
valid = false;
}
if (document.getElementById('searchRecord3').value == qdb_numrows == 0) {
if (qdb_numrows == 0) //only receive focus if its the first error
document.getElementById('searchRecord3').focus();
//change border to red on error (i would use a class change here...
document.getElementById('searchRecord3').style.border = "solid 1px red";
alert(msg = "Error: Data entered for field #3 not required for procedure code Or procedure code is not valid!\n");
valid = false;
}
if (document.getElementById('searchRecord4').value == qdb_numrows == 0) {
if (qdb_numrows == 0) //only receive focus if its the first error
document.getElementById('searchRecord4').focus();
//change border to red on error (i would use a class change here...
document.getElementById('searchRecord4').style.border = "solid 1px red";
alert(msg = "Error: Data entered for field #4 not required for procedure code Or procedure code is not valid!\n");
valid = false;
}
if (document.getElementById('searchRecord5').value == qdb_numrows == 0) {
if (qdb_numrows == 0) //only receive focus if its the first error
document.getElementById('searchRecord5').focus();
//change border to red on error (i would use a class change here...
document.getElementById('searchRecord5').style.border = "solid 1px red";
alert(msg = "Error: Data entered for field #5 not required for procedure code Or procedure code is not valid!\n");
valid = false;
}
if (document.getElementById('searchRecord6').value == qdb_numrows == 0) {
if (qdb_numrows == 0) //only receive focus if its the first error
document.getElementById('searchRecord6').focus();
//change border to red on error (i would use a class change here...
document.getElementById('searchRecord6').style.border = "solid 1px red";
alert(msg = "Error: Data entered for field #6 not required for procedure code Or procedure code is not valid!\n");
valid = false;
}
//if (!qdb_numrows==0) alert(msg);
//return false;
}