I've got 3 fields that are used to enter 6 digits code for purpose of a database (Quickbase) query. Each field needs an individual alert/msg letting the submitter know if a code is invalid. Example:"The data entered in field #1 is invalid" . I put together the snippet below which somewhat achieves the results. Problem is when I enter just 1 field of bad data the script works but when I enter more than 1 field of bad data or mix good data with bad data the script does nto work properly... Thank you for your assitance.
Here are the fields
<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">'
Here is the snippet
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;
}