0

Javascript Nub.

5つの選択ボックスの状態をチェックする関数を実行し、その値が「選択」の場合、別の値に基づいてそれらを設定する関数を実行したい. 最初の関数内でこれを行うことができますが、非常に長くなります。

短縮版。

function chek{

var tligc = document.getElementById('assigc').innerHTML;   
var tligd = document.getElementById('assigd').innerHTML;



 if(tligc == 'Select'){document.getElementById('otherAgency3').className = 'textBox';
    return setass(3);
       }      

if(tligd == 'Select'){document.getElementById('otherAgency4').className = 'textBox'
 return setass(4);
}

等、

function setass(value){  

    var KaRa = document.getElementById('assig').innerHTML;

                           if(KaRa =='Planning Officer'){
 document.getElementById('otherAgency'+[value]).options.length=0
 document.getElementById('otherAgency'+[value]).options[0]=new Option("Select", "Select", true, false)  
 document.getElementById('otherAgency'+[value]).options[1]=new Option("Situation Unit", "Situation Unit", true, false)
 document.getElementById('otherAgency'+[value]).options[2]=new Option("Management Support", "Management Support", true, false)  
         return  }
else if(KaRa =='Operations Officer'){
 document.getElementById('otherAgency'+[value]).options.length=0
 document.getElementById('otherAgency'+[value]).options[0]=new Option("Select", "Select", true, false)  
 document.getElementById('otherAgency'+[value]).options[1]=new Option("Staging Area Manager", "Staging Area Manager", true, false)
    return }
else if(KaRa =='Logistics Officer'){
 document.getElementById('otherAgency'+[value]).options.length=0
 document.getElementById('otherAgency'+[value]).options[0]=new Option("Select", "Select", true, false)  
 document.getElementById('otherAgency'+[value]).options[1]=new Option("Supply Unit", "Supply Unit", true, false)
 document.getElementById('otherAgency'+[value]).options[2]=new Option("Communications Support", "Communications Support", true, false)  
 document.getElementById('otherAgency'+[value]).options[3]=new Option("Facilities Unit", "Facilities Unit", true, false)
        return }
    else{document.getElementById('otherAgency'+[value]).options.length=0;
      return }
       }
 }    

最初のオプションを入力しますが、残りの if テストの残りのチェック関数を実行しません。関数 setass を実行し、適切な時点で再びメイン関数に戻る方法に関するポインタはありますか? 「リターン」は正しいコマンドではないと仮定しています(もし私が途中で言って、それをうまくやらないなら)。ありがとうございました

4

1 に答える 1