JavaScript - Simple Enable Button Properties

In this tutorial we will create a Simple Enable Button Properties using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...

Getting started:

This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. <style >
  7. #container{
  8. width:500px;
  9. margin-left:auto;
  10. margin-right:auto;
  11. padding:5px;
  12. }
  13. .display{
  14. border:1px solid #ccc;
  15. overflow:scroll;
  16. overflow-x:hidden;
  17. height:150px;
  18. padding:10px;
  19. margin-bottom:40px;
  20. }
  21. </style>
  22. </head>
  23. <nav class="navbar navbar-default">
  24. <div class="container-fluid">
  25. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  26. </div>
  27. </nav>
  28. <div class="col-md-3"></div>
  29. <div class="col-md-6 well">
  30. <h3 class="text-primary">JavaScript - Simple Enable Button Properties</h3>
  31. <hr style="border-top:1px dotted #ccc;"/>
  32. <div id="container">
  33. <h2>User Agreement</h2>
  34. <div class="display">
  35. These Terms will be applied fully and affect to your use of this Website. By using this Website, you agreed to accept all terms and conditions written in here. You must not use this Website if you disagree with any of these Website Standard Terms and Conditions.
  36. </div>
  37. <p><input type="checkbox" id="toggle"/> I agree with the terms and conditions.</p>
  38. <button class="btn btn-default" id="accept">Accept</button> <button class="btn btn-default">Decline</button>
  39. </div>
  40. </div>
  41. <script src="js/script.js"></script>
  42. </body>
  43. </html>

Creating the Script

This code contains the script of the application. This code will enable the button when only the checkbox is being checked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.
  1. var checkbox = document.getElementById("toggle");
  2. var accept = document.getElementById("accept");
  3. accept.disabled = true;
  4. checkbox.onchange = function(){
  5. accept.disabled = !this.checked;
  6. }
There you have it we successfully created a Simple Enable Button Properties using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment