How to get checked and unchecked checkbox value in jquery

In this tutorial, we will see how to checked and unchecked checkbox value using jquery. This is a very simple process. Just use property checked. When the checkbox is checked it will give you 'Y' else 'N'.  Here I have taken a  $(".chk").click(function()  to check the output value.

Steps to get checked and unchecked checkbox value in jquery
  • Add Jquery library
  • Add doucment.ready function.
  • Use checked property to get value
                                 

Source Code


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

    <script>
      $(document).ready(function () {       
         $(".chk").click(function () {
      var is_active = document.getElementById('chkActive').checked == true ? 'Y' : 'N'
      alert(is_active);
            });
        });
    </script>
</head>
<body>

    <label for="txtlazadaprice">Is Active</label>
    <input type="checkbox" class="chk" value="Y" id="chkActive" />

</body>
</html>



I hope your problem gets resolved if still have any doubt feel free to comment below.

Related Post

Post a Comment

Post a Comment (0)

Previous Post Next Post