2016-11-26 4 views
0

일부 코드는 작동하지 않습니다. 목록이 비활성화되지만 "제품 1"을 선택한 다음 목록을 사용하도록 설정하지 않았습니다. 선택한 다른 모든 목록을 완전히 비활성화해야합니다. 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 

내가 바로 당신이 customerproduct1product 선택 선택한 경우 선택 가능하고, 다른 경우 비활성화해야 얻을 경우 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

.

우선, 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

관련 문제