adsense

Sunday, March 13, 2022

Allow checking only one checkbox in a group

 If we want to behave the checkbox as radio buttons we can use JS as shown below.


JS

     function CheckOnce(checkbox) {

          $("[id$='_chkLocations']").each(function (i, obj) {

              if (obj !== checkbox) obj.checked = false

              if (obj.checked) {

                 //do something

             }

          });

      }


HTML

<input type="checkbox" ID="chkLocation" onclick="CheckOnce(this)">

<input type="checkbox" ID="chkLocation" onclick="CheckOnce(this)">


Cheers

Samitha

 

No comments:

Post a Comment