I have a requirement wherein if checkbox is true
, picklist field must be enabled. If checkbox is false
, picklist field must be disabled. But in default, picklist field must be disabled.
Enabling/disabling of picklist field is controlled by a javascript function also embedded in my visualforce page. However, each time I click the checkbox field, picklist field remained disabled.
How can I make this work with regards to the html tags inside the visualforce page?
Vf page portion:
<apex:column headerValue="Checkbox Field">
<center>
<table>
<tr>
<td><apex:inputcheckbox id="cb" value="{!acc.Checkbox_Field__c}" onclick="check(this)"/></td>
</tr>
</table>
</center>
</apex:column>
<apex:column headerValue="Picklist Field">
<center>
<table>
<tr>
<apex:selectList id="pf" value="{!acc.Picklist_Field__c}" disabled="true" size="1">
<!--PickListFields came from a method in apex class....-->
<apex:selectOptions value="{!PickListFields}"/>
</apex:selectList>
</tr>
</table>
</center>
</apex:column>
Javascript:
<script>
function check(obj)
{
if((obj.checked == true)){
document.getElementById('{!$component.pf}').disabled=false;
}
else{
document.getElementById('{!$component.pf}').disabled=true;
}
}
</script>