0

I have this checkbox.

What I want is that when I click New it would disable the Old checkbox and vice versa. By the way, this is a repeated checkbox, then when I click the Submit Button, it will retain the checkbox that I checked, so that when I forgot something I can choose again. Unchecking the new/old will enable both checkboxes again. And back to first again that when I check it would disable the other one. A jQuery/JavaScript solution will do.

New / OLD
[x]  [ ] English
[ ]  [x] Math
[x]  [ ] Science

Submit Button

<table>
    <apex:repeat value="{!voucherList}" var="b" id="theRepeat"> 
    <tr>
        <td style="text-align: center;" >
            <apex:inputCheckbox value="{!b.newExam}" onclick="check(this)"  id="checkBox" />
        </td>
        <td style="text-align: center;" >
            <apex:inputCheckbox value="{!b.oldExam}" onclick="disable(this)"  id="retake" />
        </td>
    </tr>
    </apex:repeat>
</table>

<apex:commandButton style=" margin-top:80px; text-align:center;" status="status" value="Submit Request" action="{!submitCase}" reRender="myForm"/>
1

Please, try it:

<table>
    <apex:repeat value="{!voucherList}" var="b" id="theRepeat"> 
    <tr>
        <td style="text-align: center;" >
            <apex:inputCheckbox value="{!b.newExam}" onclick="changeState({! 'retake' + b.oldExam})"  id="{! 'checkBox' + b.newExam}" />
        </td>
        <td style="text-align: center;" >
            <apex:inputCheckbox value="{!b.oldExam}" onclick="changeState({! 'checkBox' + b.newExam})"  id="{! 'retake' + b.oldExam}" />
        </td>
    </tr>
    </apex:repeat>
</table>

<apex:commandButton style=" margin-top:80px; text-align:center;" status="status" value="Submit Request" action="{!submitCase}" reRender="myForm"/>

and js something like this:

<script>
    function changeState(idCheckboxToSet) {
      $("#" + idCheckboxToSet).removeAttr("checked");
    }
</script>

Let me know if this help you ; )

| improve this answer | |
0

You can solve this using javascript in VF Page. Try the following:

<script>
         function enableDisable(cb)
    {
      $("input:checkbox[id*=looped]").removeAttr('checked');
      $(cb).attr('checked', 'checked');
    }

</script>
<apex:inputCheckBox id="looped" value="{!ask.isSelected}" onclick="enableDisable(this)"/>
| improve this answer | |
  • its not working – Sony PSP May 1 '17 at 15:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.