Friday 26 September 2014

How to select only one checkbox value in visualforce page using javascript

Here is the code to select only one checkbox value in visualforce page by accessing DOM ID
Using the javascript and onchange event.
  1. <apex:page >
  2.     <apex:form >
  3.         <script>
  4.         function confirmDisbaled(ifchecked, id1 ,id2,id3) {
  5.             document.getElementById(id1).disabled = ifchecked;
  6.             document.getElementById(id2).disabled = ifchecked;
  7.             document.getElementById(id3).disabled = ifchecked;
  8.         }
  9.         </script>
  10.         <apex:pageBlock >
  11.             <apex:actionRegion >
  12.                 <apex:outputPanel id="panel1">
  13.                     <apex:pageBlockSection title="PST" id="PST">
  14.                        
  15.                         <apex:inputCheckbox label="Global" id="gbl" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.cntry}');"/>
  16.                         <apex:inputCheckbox label="Local" id="lcl" onchange="return confirmDisbaled(this.checked, '{!$Component.gbl}','{!$Component.cntry}');"/>
  17.                         <apex:inputCheckbox label="Country" id="cntry" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.gbl}');"/>
  18.                        
  19.                     </apex:pageBlockSection>
  20.                 </apex:outputPanel>
  21.             </apex:actionRegion>
  22.         </apex:pageBlock>
  23.     </apex:form>
  24. </apex:page>

3 comments:

  1. How can we apply the tech to dynamic element? For instance, when we lookup account, the related contact will be showed below, so how can we apply the tech to the dynamic checkbox?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...