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

 

Thursday, March 10, 2022

Adding visibility attribute

 There are two ways to add the visibility attribute for an element. They have a difference in the way it renedered in the HTML as shown below.


  1. $("#elementid").attr("style", "visibility: hidden")

  This will be rendered as 

style="visibility: hidden;"

 2. $("#elementid").css("visibility", "hidden")

  This will be rendered as 

style="width: 50px; color: red; visibility: hidden;"

 

 

In summary the first one will set the style attribute and the second one will append to the existing style attribute.


Cheers

Samihta