0

データベース (Quickbase) クエリの目的で 6 桁のコードを入力するために使用される 3 つのフィールドがあります。各フィールドには、コードが無効かどうかを提出者に知らせる個別のアラート/メッセージが必要です。例:「フィールド #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;
}
4

0 に答える 0