How to check whether a checkbox is checked in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To check whether a checkbox is checked, try to run the following code. It returns true if the checkbox is checked, else false −

Example

Live Demo

<html>
   <head>
      <script>
         function myFunction(){
            var result = document.getElementById("check").checked;
            alert(result);
         }
      </script>
   </head>
   <body>
      <label><input id="check" type="checkbox" >One</label><br>
      <button onclick="myFunction()">Check value</button>
   </body>
</html>
raja
Published on 01-Feb-2018 15:24:00
Advertisements