-8

Cold Fusion と統合された従来の JS 関数を使用して、if ステートメントでラップされた n 番目の ID フォーム フィールドを出力します。出力が非常に高く、非常に冗長で扱いにくい場合があります。for ループでこれを修正できると考えていますが、それに取り組む正しい方法がわかりません。以下は、サンプル出力からの従来のコードです。どんな助けでも大歓迎です:

function checkFinalDisposition(){
if (document.getElementById("mrostatus").value == "Completed"){


    var checkfinal = document.getElementById("finaldisposition").value
    if (checkfinal == 'NEGATIVE' || checkfinal == 'NEGATIVE DILUTE'){
        var checkfinalpass = 'Yes'

        if (document.getElementById("id4735721").value != 'NEGATIVE' || document.getElementById("id4735721").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
        if (document.getElementById("id4735722").value != 'NEGATIVE' || document.getElementById("id4735722").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
        if (document.getElementById("id4735723").value != 'NEGATIVE' || document.getElementById("id4735723").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
        if (document.getElementById("id4735724").value != 'NEGATIVE' || document.getElementById("id4735724").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
        if (document.getElementById("id4735725").value != 'NEGATIVE' || document.getElementById("id4735725").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
        if (document.getElementById("id4735726").value != 'NEGATIVE' || document.getElementById("id4735726").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
        if (document.getElementById("id4735727").value != 'NEGATIVE' || document.getElementById("id4735727").value != 'NEGATIVE DILUTE'){
            var checkfinalpass = 'No'
        }
    }
    else{
        var checkfinalpass = 'No'
        //Multiple IF's from drug query

        if (document.getElementById("id4735721").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

        if (document.getElementById("id4735722").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

        if (document.getElementById("id4735723").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

        if (document.getElementById("id4735724").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

        if (document.getElementById("id4735725").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

        if (document.getElementById("id4735726").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

        if (document.getElementById("id4735727").value == checkfinal){
            var checkfinalpass = 'Yes'
        }

    }

    if (checkfinalpass != 'Yes'){
        var inputfinaldisposition = 'NEGATIVE'
        //Multiple IF's from drug query

        if (document.getElementById("id4735721").value == ""){
            document.getElementById("id4735721").value = "POSITIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735721").value != 'NEGATIVE' || document.getElementById("id4735721").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735721").value
        }

        if (document.getElementById("id4735722").value == ""){
            document.getElementById("id4735722").value = "POSITIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735722").value != 'NEGATIVE' || document.getElementById("id4735722").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735722").value
        }

        if (document.getElementById("id4735723").value == ""){
            document.getElementById("id4735723").value = "NEGATIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735723").value != 'NEGATIVE' || document.getElementById("id4735723").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735723").value
        }

        if (document.getElementById("id4735724").value == ""){
            document.getElementById("id4735724").value = "NEGATIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735724").value != 'NEGATIVE' || document.getElementById("id4735724").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735724").value
        }

        if (document.getElementById("id4735725").value == ""){
            document.getElementById("id4735725").value = "NEGATIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735725").value != 'NEGATIVE' || document.getElementById("id4735725").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735725").value
        }

        if (document.getElementById("id4735726").value == ""){
            document.getElementById("id4735726").value = "NEGATIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735726").value != 'NEGATIVE' || document.getElementById("id4735726").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735726").value
        }

        if (document.getElementById("id4735727").value == ""){
            document.getElementById("id4735727").value = "NEGATIVE";
        }
        if ((inputfinaldisposition == 'NEGATIVE' || inputfinaldisposition == 'NEGATIVE DILUTE') && (document.getElementById("id4735727").value != 'NEGATIVE' || document.getElementById("id4735727").value != 'NEGATIVE DILUTE')){
        var inputfinaldisposition = document.getElementById("id4735727").value
        }

        var answer = confirm("Please advise the Final Disposition does not match your individual results!\n\nPress \"OK\" to change Final Disposition to "+inputfinaldisposition)

        if (answer){
            document.getElementById("finaldisposition").value = inputfinaldisposition;
            return true;
        }
        else{
            return false
        }
    }
}
}
4

1 に答える 1

1

私はあなたがチェックしているIDのjs配列を持っているでしょう、

idToCheck = ['id4735721', 'id4735722', ...];

次に、それらを for ループで比較します。

for(id in idToCheck){
      if($('#'+idToCheck[id]).val() != 'NEGATIVE' || if($('#'+idToCheck[id]).val() != 'NEGATIVE DILUTE'){
            checkfinalpass = 'No';
      }
}

私はあなたのコード全体をやり直したわけではありませんが、これがあなたを正しい方向に導くことを願っています.

于 2013-02-07T18:34:26.207 に答える