I've a VF page; in which i 've to allow user to select only one checkbox. when user select one checkbox, it should deselect another checkbox. i've to add row on vf as per requirement(as shown in img). how can i do this.

My VF page code ;

<apex:pageBlockSection title="Client Attendees" columns="1">

    <apex:outputPanel id="clientAttendeesPanel">
      <apex:variable var="iterator" value="{!0}"/>
      <apex:pageBlockTable value="{!clientAttendees}" var="attendee">

        <!-- Actions -->
        <apex:column headerValue="Actions" style="width:10px">
          <apex:commandLink onclick="if (window.confirm('Are you sure?')) onDeleteClientAttendee({!iterator}); return false;"
          <apex:variable var="iterator" value="{!iterator + 1}"/>

        <!-- Contact Name -->
        <apex:column headerValue="Contact Name" style="width:10px">
          <apex:inputField value="{!attendee.Contact_Name__c}" id="clientAttendee">
            <a href="javascript:openQuickCreateClientAttendee('{!$Component.clientAttendee}', '{!$Component.targetId}')" class="createLink">
              Create Client Attendee

        <!-- Primary Client Attendee -->
        <apex:column headerValue="Primary Client Attendee">
          <apex:inputField value="{!attendee.Primary_Client_Attendee__c}" style="width:300px"/>

    <apex:pageBlockSectionItem >
      <apex:outputLink styleClass="createLink" onclick="onAddClientAttendee(); return false;">
        + Add another Client Attendee


VF page screen shot is

enter image description here

  • Do a search for onecheck. This has been asked and answered but cannot figure out how to get duplicate on mobile
    – Eric
    Aug 24, 2016 at 7:39
  • The above is working fine. But the whole page checkboxes are unchecked. Can you help me how to write the code for specific section in a vf page
    – user43293
    Mar 24, 2017 at 16:29

1 Answer 1


You can add an onchange event for the checkbox field to check the value of the checkbox, and uncheck all the other checkboxes if required:

<apex:inputField value="{!attendee.Primary_Client_Attendee__c}" style="width:300px" onchange="oneCheckbox(this);" />

function oneCheckbox(obj)
    if (obj.checked)
        var inputs = document.getElementsByTagName("input");

        for (var i = 0; i < inputs.length; i++)
            var oInput = inputs[i];
            if (oInput.type == "checkbox" && oInput.checked && oInput != obj)
                oInput.checked = false; 


This script finds -every- checkbox field on the page and unchecks them as required, so if you have other checkboxes that shouldn't be checked you will need to add a more specific document selector.



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .