You can use below code to disable or enable input fields in VF page on click of checkbox :
Visualforce
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <apex:page controller="checkboxCtrl"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("[id$=myCheckbox]").change(function(){ if(this.checked==true){ $("[id$=mytextinput]").prop("disabled",true); } else{ $("[id$=mytextinput]").prop("disabled",false); } }); }); </script> <apex:form> <apex:pageblock> <apex:pageBlockSection> <apex:pageBlockSectionItem> <apex:outputPanel styleClass="requiredInput" layout="block"> <apex:inputField id="mytextinput" value="{!acc.Name}"/> <apex:inputCheckbox id="myCheckbox" /> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> |
Output
If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !
Thanks
Keep Coding
0 Comments