2016-08-18 4 views
0

私は他のドロップダウン(selectA)で選択された選択に応じて、ドロップダウン(selectB)でいくつかのオプションを取り除こうとしています。 残念ながら私の解決策は機能しません。誰かがヒントを持っていますか? a132は最初のドロップダウンで指定したオプションです。このオプションを選択している場合は、オプションb01とb03を2番目のドロップダウンから削除する必要があります。 getridofoptions()はonChangeと呼ばれます。 bo2、bo4、b05、b06はドロップダウンに留まります。ユーザーが最初のドロップダウンで選択を変更した場合は、可能なすべてのオプションを再度アクティブにする必要があります(これを行うには接着剤を使用しないでください)。この後、getridofoptionsは、新しい選択に従ってオプションを削除する必要があります。 例:selectAがa132からa133に変更された場合、オプションb01、b02、b04はキックバックされ、b03、b05、b06は維持されるべきです。あなたのコードは大丈夫です任意のサポート/アイデアを TankfulゲオルクドロップダウンリストからIDを削除しますか?

function getridofoptions() { 
 
    if (document.getElementById('a132').selected == True) { 
 
    var x = document.getElementById("b01"); 
 
    x.remove(x.selectedIndex); 
 
    var x = document.getElementById("b02"); 
 
    x.remove(x.selectedIndex); 
 
    var x = document.getElementById("b04"); 
 
    x.remove(x.selectedIndex); 
 
    } else {} 
 
    if (document.getElementById('a133').selected == True) { 
 
    var x = document.getElementById("b01"); 
 
    x.remove(x.selectedIndex); 
 
    var x = document.getElementById("b03"); 
 
    x.remove(x.selectedIndex); 
 
    } else {} 
 
}
<select id="selectA" name="Size" onchange="ReadForm (this.form, false);getridofoptions();"> 
 
    <option value="" id="a00" selected>1. W&auml;hlen Sie Ihre Variante</option> 
 
    <option value="a &szlig alabla" id="a130">wei&szlig; 5,00 EUR</option> 
 
    <option value="b &szlig blabla" id="a131">wei&szlig; 6,00 EUR</option> 
 
    <option value="c &szlig clabla" id="a132">wei&szlig; 7,00 EUR</option> 
 
    <option value="d &szlig dlabla" id="a133">wei&szlig; 8,00 EUR</option> 
 
    <option value="e &szlig eabla" id="a134">wei&szlig; 9,00 EUR</option> 
 
</select> 
 

 
<br> 
 
<select id="selectB" name="Options" onchange="ReadForm (this.form, false);getridofoptions();"> 
 
    <option value="" id="b99" selected>2. W&auml;hlen Sie aus:</option> 
 
    <option value="Test ha" id="b01">Test ha</option> 
 
    <option value="Test ho" id="b02">Test ho</option> 
 
    <option value="Test hk" id="b03">Test hk</option> 
 
    <option value="Test kl" id="b04">Testreihe kl</option> 
 
    <option value="Test km" id="b05">Testreihe km</option> 
 
    <option value="Test lo" id="b06">Testreihe lo</option> 
 
</select>

答えて

0

は、あなただけのtrueTrueを変更する必要があります。現在、一致することのないboolstringを比較しようとしています。 (選択のdocument.getElementById(「A132」)。)

function getridofoptions() 
{ 
    if(document.getElementById('a132').selected==true) 
    { 
     var x = document.getElementById("b01"); 
     x.remove(x.selectedIndex); 
     var x = document.getElementById("b02"); 
     x.remove(x.selectedIndex); 
     var x = document.getElementById("b04"); 
     x.remove(x.selectedIndex); 
    } 
    else 
    { 
    } 
    if(document.getElementById('a133').selected==true) 
    { 
     var x = document.getElementById("b01"); 
     x.remove(x.selectedIndex); 
     var x = document.getElementById("b03"); 
     x.remove(x.selectedIndex); 
    } 
    else 
    { 
    } 
} 
+0

それとも__'if '__のように... – Rayon

+0

@Rayonはイエス正確けどOPはちょうど私が書いたことを明確にするように、初心者のようです完全な声明。 – Mairaj

+0

ご協力いただきありがとうございます。あなたは私のルーキーです。削除は今のところうまくいくようです:-)私の問題:私はまだすべてのオプションを生き返らせる方法を知りません。ユーザーがselectAで選択を変更してから、スクリプトを再実行して新しい選択肢にオプションを削除するまでのステップ。 @レオパード:私はあなたの文 "現在あなたは一致しない文字列をboolと比較しようとしています"ということは分かりません。あなたは説明するのがとても親切でしょうか? – Georg

関連する問題