1

This question already has an answer here:

I have a visual force page which dynamically displays multiple records with check box's. I need to allow the user to select only one check box at a time.

I know it is possible with only javascript. Can any one post sample code for this? If you have any other suggestions as well, please let me know.

marked as duplicate by Eric, superfell, sfdcfox, cropredy, crmprogdev Nov 22 '15 at 6:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
    You can use radio button instead of checkbox – Anita Bhanarkar Apr 17 '15 at 15:32
  • I tried that as well, but they were not populating correctly because the records are populating dynamically. – user3708392 Apr 17 '15 at 15:41
  • 3
    Try posting your attempt at doing this and ask for any other suggestions as well for it. Usually, this site requests that Users produce a specific attempt at coding their problem along with the question. Alternatively, if you are asking for different ways on how to do this, you could post that as a separate question. Something along the lines of: I know that I can use javascript to enforce only a single checkbox checked at a time, but is there any other ways to do so as well? Please produce a list and short description if possible. – dphil Apr 17 '15 at 16:58
1

There are many ways. But the best solution is to get it working with checkboxes. Other ways are,

1 - Write page level javascript to ensure that only one checkbox is checked. Get element by class, iterate over it and ensure that only one is checked. This javascript method should be called whenever user click on checkbox.

2 - Write actionfunction to check that only one field is checked using a controller function. Call it whenever user clicks checkbox.

  • 1
    or option 3 - onchange event with actionSupport to controller that unchecks all other boxes and then returns null to refresh page (or actionRegion); I use a variation of #1 with jQuery – cropredy Apr 17 '15 at 18:40
1

I'm a little late to the party on this one but I had the same issue and could not find a complete solution, so I came up with my own and made a blog post about it here

The solution uses a couple of lines of jQuery, but is fairly straightforward.

Hopefully that post will help anyone having the same issue in the future.

  • Not too late for my party, Chris. Thanks for making this blog as I put this issue on the 'back-burner'. I'll try it out and get back to you how it works. Thanks again! – user3708392 May 12 '15 at 15:16
  • No problem, glad I could help. – Chris Aldridge May 13 '15 at 15:25

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