+ Start a Discussion
saimadhusaimadhu 

how to select one checkbox and then deselct the other

Hi,

In a table I placed two checkboxes yes and no .if i click yes then checkbox NOshould deselect(if it already selected).

if a click  checkbox  NO it should deselect YES.

Here is my vf page:

<table class="list" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr border="1" class="dataRow even first" onblur="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onmouseover="if (window.hiOn){hiOn(this);}">
<td> </td>
<td> Higher Capacity Circuit </td>
<td class="actionColumn"><apex:inputCheckbox value="{!prihighcapacity}" id="checkyes" immediate="true">YES
<apex:actionSupport event="onclick" action="{!highcapacity}" rerender="PRIcapacity">
<apex:param name="checkyes" value="true" assignTo="{!yescheck}" />
</apex:actionSupport>
</apex:inputCheckbox>
</td>
<td class="actionColumn"><apex:inputCheckbox value="{!prinohighcapacity}" id="checkno" immediate="true">NO
<apex:actionSupport event="onclick" action="{!nohighcapacity}" rerender="PRIcapacity">
</apex:actionSupport>
</apex:inputCheckbox>
</td>
</tr>
</tbody>
</table>

 

the controller is:

public void highcapacity() {



if(prihighcapacity == true){
prinohighcapacity = false;
}

}

public void nohighcapacity(){


if(prinohighcapacity == true){
prihighcapacity = false;
}

}

 but it is not working as i expect if i click yes and then click no both are selecting .

we shuold select either one.any suggestion please.

Best Answer chosen by Admin (Salesforce Developers) 
S91084S91084

Hi instaed of using <apex:intputCheckbox/> use <apex:selectRadio/>. For the opions, use yes and no. When you select yes, no will be deselected and when you select no, yes will be deselected.

 

You can refer to the Component Reference to find the example how to use <apex:selectRadio/>

All Answers

S91084S91084

Hi instaed of using <apex:intputCheckbox/> use <apex:selectRadio/>. For the opions, use yes and no. When you select yes, no will be deselected and when you select no, yes will be deselected.

 

You can refer to the Component Reference to find the example how to use <apex:selectRadio/>

This was selected as the best answer
saimadhusaimadhu

thank you so much