2010-03-29 2 views
0

드롭 다운 상자와 그 아래에 일부 텍스트 입력 필드가 있습니다. 사용자가 선택한 드롭 다운 메뉴의 항목을 기반으로 일부 필드를 비활성화하려고합니다. 내가 올바르게 입력 필드를 대상으로 실패하고 생각하지만 난 문제가 무엇인지 알아낼 수 없습니다 :드롭 다운에서 선택에 따라 입력 필드 사용 안 함

$(document).ready(function(){ 
var customfield = $('#customfields-tf-19-tf'); 
var customfield1 = $('#customfields-tf-20-tf'); 
var customfield2 = $('#customfields-tf-13-tf'); 


$(function() { 
    var call_table = { 
    'Condominium': function() { 
    customfield.attr("disabled");  
    }, 
    'Co-Op': function() { 
    customfield1.attr("disabled"); 
    }, 
    'Condop': function() { 
    customfield2.attr("disabled"); 
    } 
    }; 

    $('#customfields-s-18-s').change(function() { 
    call_table[this.value](); 
    }); 

}); 

}); 

그리고 내 양식의 레이아웃 : 여기

은 지금까지 입수했습니다 스크립트입니다 :

내가 입력을 해제하기 위해 사용할 필요가 있다고 생각
<td width="260" class="left"> 
<label for="customfields-s-18-s">Ownership (Required):</label> 
</td> 
<td class="right"> 
<select name="customfields-s-18-s" class="dropdown" id="customfields-s-18-s" size="" > 
<option value="Condominium"> Condominium</option> 
<option value="Co-Op"> Co-Op</option> 
<option value="Condop"> Condop</option> 
</select> 
</td> 
</tr> 



<tr> 
<td width="260" class="left"> 


    <label for="customfields-tf-19-tf">Maintenance:</label> 
</td> 
<td class="right"> 
    <input type="text" title="Maintenance" class="textInput" name="customfields-tf-19-tf" id="customfields-tf-19-tf" size="40"/> 
</td> 

</tr> 


<tr id="newsletter_topics"> 
<td width="260" class="left"> 

    <label for="customfields-tf-20-tf">Taxes:</label> 
</td> 
<td class="right"> 
    <input type="text" title="Taxes" class="textInput" name="customfields-tf-20-tf" id="customfields-tf-20-tf" size="40" /> 
</td> 
</tr> 


<tr> 
<td width="260" class="left"> 

    <label for="customfields-tf-13-tf" class="required">Tax Deductibility:</label> 
    </td> 
<td class="right"> 
    <input type="text" title="Tax Deductibility" class="textInput" name="customfields-tf-13-tf" id="customfields-tf-13-tf" size="40" /> 
</td> 
</tr> 
+0

당신을 제안 태그 "jQuery"를 추가하십시오. –

답변

1

:

$(input).attr("disabled", "disabled"); 

또한, 이러한 기능 중 일부는 당신을 위해 유용 할 수 있습니다 그들이 정의 된 일단

$.fn.enable = function() { 
    return this.removeAttr('disabled'); 
} 

$.fn.disable = function() { 
    return this.attr('disabled', 'disabled'); 
} 

$.fn.disenable = function(val) { 
    if (val) 
    return this.enable(); 
    else 
    return this.disable() 
} 

$.fn.toggleEnabled = function() { 
    if (this.attr('disabled') == 'disabled') 
    return this.enable(); 
    else 
    return this.disable(); 
} 

, 당신은 다음과 같이, 어떤 jQuery를 변수에 사용할 수 있습니다 :

$(input).toggleEnabled(); 
+0

굉장, 내가 뭘 찾고 있었는지 - 그리고이 다른 기능들은 완전히 내 다음 질문에 감사한다! – Thomas

관련 문제