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"/>

closed as off-topic by Eric, crmprogdev, Brian Mansfield, Mohith Shrivastava, Himanshu May 2 '17 at 6:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Eric, crmprogdev, Brian Mansfield, Mohith Shrivastava, Himanshu
If this question can be reworded to fit the rules in the help center, please edit the question.

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 ; )

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)"/>
  • 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.