2016-11-26 19 views
0

私のコードは一部機能しています。リストは無効になりますが、私は "product1"を選択してリストを有効にしていることに気づいていません。選ばれたものはリストを完全に無効にするべきです。 ID製品のリスト。だから私はそれが正しい方法を書いているかどうかわからない、選択されたオプションのための私の構文で何かだと思います。オプションが選択されている場合はリストを無効にする

VBScriptの

'Disables or enables list based on selection 
Function enabler() 
    For Each opt In document.GetElementByID("customer").Options 
     If opt.Selected = "product1" Then 
      document.GetElementByID("product").Disabled = False 
     Else 
      document.GetElementByID("product").Disabled = True 
     End If 
    Next 
End Function 

HTA

... 
<select size="5" id="product" name="ListboxUserRole" onChange="SaveListboxUserRoleValue"> 
    <option value="1" selected="selected">product1</option> 
    <option value="2">product2</option> 
    <option value="3">product3</option> 
... 
<select size="5" id="customer" name="ListboxCustomer" onChange="SaveListboxCustomerValue" value="1"> 
    <option value="1" selected="selected">customer1</option> 
    <option value="2">customer2</option> 
    <option value="3">customer3</option> 
    <option value="4">customer4</option> 
... 
+0

、あなたの完全なHTAのコードで更新することができます。

Sub enabler() Dim opt Dim match For Each opt In product.options match = opt.selected And opt.label = "product1" If match Then Exit For Next customer.disabled = Not match End Sub 

enabler()は、それに呼び出しを追加し、customer変化に呼び出されなければなりませんか? –

+0

非常に大きいですが、私は体の負荷の関数を呼び出しています。 – Avean

+0

したがって、 'customer'リストから' product1'を選択したとき、 'product'リスト全体を無効にしたいのですか? –

答えて

0

私は右のそれを取得する場合、あなたはproduct1productで選択されている場合customerを選択し有効にする必要があります]を選択し、他の場合には無効。

まずは,product選択イベントは、SaveListboxCustomerValue()にリンクされています。 customer選択無効をSaveListboxCustomerValue()以内に処理する必要がある場合は、<body onload="enabler()">をちょうど<body>に置き換えてください。

product選択したオブジェクトのselectedIndexプロパティを使用するアルゴリズムを手直しするIMOよりよいが、enabler()は、必要ありません。 enabler()削除、およびSaveListboxCustomerValue()に変更を加えます。

Sub SaveListboxCustomerValue() 

    ' enable customer if the first item in product selected 
    customer.disabled = product.selectedIndex <> 0 

    ' the rest part of the code 

End Sub 

をそうでない場合、あなたはenabler()を維持したい場合は、次に約Option Object Propertiesをお読みください。ブール値が文字列"product1"と決して等しくないので、常に現在の状態はFalseを返します。コードは次のようにする必要があります:

Sub SaveListboxCustomerValue() 

    enabler() 

    ' the rest part of the code 

End Sub 
+0

何を問わずリストを無効にします。選択された製品1は引き続き使用できません。 – Avean

+0

@Avean代替ソリューションを追加しました。 – omegastripes

+0

本当にいい:)それはトリックでした。しかし、私がproduct1に戻って再び変更した場合、それはリストを再度有効にしません。今すぐproduct1を選択するとリストがアクティブになり、他のすべてのオプションは無効になります。すべての良い。しかし、プロダクト1に戻っても、リストはまだ無効になっています。任意のヒント? – Avean

関連する問題