You are viewing limited content. For full access, please sign in.

Question

Question

Is there a JavaScript for a user to make only one selection?

asked on May 8, 2018

I have a table similar to the one below where a user will make a selection.  I am in need of a JavaScript code that will only allow one selection to be checked.  

Any ideas would be appreciated!  Thanks.  Pete

0 0

Replies

replied on May 8, 2018 Show version history

First, find out what the ids of the checkbox inputs in that column are. They should all start with the same prefix FieldN. In my example, all four checkboxes start with Field24. Screenshot shows how this looks in the Chrome inspector.

Once you have the id prefix, the following function should do it:

$(document).ready(function () {
  $('input[id^=Field24]:not(:checked)').change(function() {
    $('input[id^=Field24]').not(this).prop('checked', false);
  });
  
});

Replace Field24 with whatever your prefix is.

0 0
replied on May 9, 2018

Thank you for your help Leif.  Pete

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.