+ Start a Discussion
KK@HelloKK@Hello 

Disabling checkboxes

I have a VF page where are fileds are checkboxes. I need to disable other checkboes in a section if one is selected.

Can somebody tell me how to get this working?

 

I have addded my code. Nothing is happening on my vf page.Pls suggest how to do it:

 

<apex:actionRegion >
        <apex:outputPanel id="panel1">  
        <apex:pageBlockSection title="PST" id="PST">
            <apex:inputCheckbox label="Global" selected="true" value="{!global}"/>
             <apex:actionsupport event="onchange" action="{!setPST}" rerender="panel1" status="StatusChange" />
            <apex:inputCheckbox label="Local" value="{!local}"/>
             <apex:actionsupport event="onchange" action="{!setPST}" rerender="panel1" status="StatusChange" />

            <apex:inputCheckbox label="Country" value="{!con}"/>
              <apex:actionsupport event="onchange" action="{!setPST}" rerender="panel1" status="StatusChange" />

         </apex:pageBlockSection>
         </apex:outputPanel>          
</apex:actionRegion>


class:

 

public class checkbox{

public Boolean globalct{get; set;}
 public Boolean local{get; set;}
 public Boolean con{get; set;}

 private String previousPSType = 'global';

public New_Appointment(ApexPages.StandardController controller) {}

 public void setPSType(){
        if (global== true && previousPSType != 'global') {
            previousPSType = 'global';
            local= false;
            con= false;
        } else if (local== true && previousPSType != 'local') {
            previousPSType = 'local';
            global= false;
            con= false;
        } else if (con== true && previousePSType!= 'con') {
            previousPSType = 'con';
            local= false;
            global= false;
        }} 

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Hi 

    Try this ... just create new page and paste it .

                     

<apex:page>
<apex:form>
<script>
function confirmDisbaled(ifchecked, id1 ,id2,id3) {


document.getElementById(id1).disabled = ifchecked;
document.getElementById(id2).disabled = ifchecked;
document.getElementById(id3).disabled = ifchecked;


}
</script>
<apex:pageBlock>
<apex:actionRegion >
<apex:outputPanel id="panel1">
<apex:pageBlockSection title="PST" id="PST">
<apex:inputCheckbox label="Global" id="gbl" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.cntry}');"/>

<apex:inputCheckbox label="Local" id="lcl" onchange="return confirmDisbaled(this.checked, '{!$Component.gbl}','{!$Component.cntry}');"/>

<apex:inputCheckbox label="Country" id="cntry" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.gbl}');"/>

</apex:pageBlockSection>
</apex:outputPanel>
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Did this answers your questions...if so please mark it solved

 

Thanks

asish

  

All Answers

kranjankranjan
Hi KK,

You can either use the ActionSuport VF tag and use onchange event to send postback where you can disable the other 2 checkboxes can then be shown disabled. You can use the disabled attribute for inputChekBox VF tag for this.

Alternatively you can use javascript and use normal onChange event for the control to call the javascript function which can disable the other 2 checkboxes.

hope that helps.
JitendraJitendra

Hi Kamal,

 

If this is the scenario where you want only one selection than use HTML radio button.

In case of checkbox, write the Javascript code at the bottom of page to disable other checkboxes.

 

If still you are not able to figure out then please post the VF code here.

asish1989asish1989

Hi 

    Try this ... just create new page and paste it .

                     

<apex:page>
<apex:form>
<script>
function confirmDisbaled(ifchecked, id1 ,id2,id3) {


document.getElementById(id1).disabled = ifchecked;
document.getElementById(id2).disabled = ifchecked;
document.getElementById(id3).disabled = ifchecked;


}
</script>
<apex:pageBlock>
<apex:actionRegion >
<apex:outputPanel id="panel1">
<apex:pageBlockSection title="PST" id="PST">
<apex:inputCheckbox label="Global" id="gbl" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.cntry}');"/>

<apex:inputCheckbox label="Local" id="lcl" onchange="return confirmDisbaled(this.checked, '{!$Component.gbl}','{!$Component.cntry}');"/>

<apex:inputCheckbox label="Country" id="cntry" onchange="return confirmDisbaled(this.checked, '{!$Component.lcl}','{!$Component.gbl}');"/>

</apex:pageBlockSection>
</apex:outputPanel>
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Did this answers your questions...if so please mark it solved

 

Thanks

asish

  

This was selected as the best answer
KK@HelloKK@Hello

Thanks  asish1989 :)