Hi Tanu,
Try this code
- Using apex input checkbox and apex input text
VF page
<apex:page controller=”DisableInputTextCntrl”>
<script>
function myFunction(checkboxId){
var flag = document.getElementById(checkboxId).checked;
callAction(flag);
}
</script>
<apex:form>
<apex:actionFunction name=”callAction” reRender=”yourText” action=”{!changeFlag}”>
<apex:param value=”” name=”flagValue”/>
</apex:actionFunction>
<apex:inputCheckbox id=”yourBox” styleClass=”test” onclick=”myFunction(‘{!$Component.yourBox}’)”/>
<apex:inputText id=”yourText” disabled=”{!(!flag)}”/>
</apex:form>
</apex:page>
Controller
public class DisableInputTextCntrl {
public boolean flag{get;set;}
public DisableInputTextCntrl(){
flag = false;
}
public void changeFlag(){
flag = boolean.valueOf(ApexPages.currentPage().getParameters().get(‘flagValue’));
}
}
2. Using HTML input checkbox and input text
VF page
<apex:page>
<input type=”text” id=”yourText” disabled=”true” />
<input type=”checkbox” id=”yourBox” />
<script>
document.getElementById(‘yourBox’).onchange = function() {
document.getElementById(‘yourText’).disabled = !this.checked;
};
</script>
</apex:page>