function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NatrajNatraj 

Checkbox field in VF page

Hi All,

 

I have two check boxes named A and B  in my custom object. In my visualforce page

If I select A then B should be unselected and vice versa.

 

How to do this?

 

I don't want  to use picklist at the backend and use select option at the front end.

 

I want to use only checkboxes.

 

Pls help me in this.

Prafull G.Prafull G.

If you want to use Checkbox only and same time want functionality like radio button, then you can write some javascript to do this for you.

<apex:page>
  <script>
   function uncheckOther(elm) {
     // first set noth checkbox as unchecked (reset)
     document.getElementById('{!$Component:frm:inptCheck1}').checked=false;
     document.getElementById('{!$Component:frm:inptCheck2}').checked=false;
      // then set the current one as checked
      elm.checked=true;
    }
  </script>

  <apex:form id="frm">
    <apex:inputCheckbox id="inptCheck1" value="{!yourObj.A__c}" onClick="uncheckOther(this)"/>
    <apex:inputCheckbox id="inptCheck2" value="{!yourObj.B__c}" onClick="uncheckOther(this)"/>
  </apex:form>
</apex:page>

Let me know if this helps.