Core JavaScript

Disabling and Enabling a Button

This JavaScript program shows how to disable and enable a button by using the onclick event and handler function.

DisableButton.html

<!DOCTYPE html>
<html>
<head>
  <title>XoaX.net's Javascript</title>
  <script type="text/javascript">
    function DisableButton() {
      document.getElementById('idAlert').disabled = !(document.getElementById('idAlert').disabled);
    }
    function ShowAlert() {
      alert("I am enabled.");
    }
  </script>
</head>
<body>
  <button onclick="DisableButton()">The Disabler</button>
  <button id="idAlert" onclick="ShowAlert()">Alert</button>
</body>
</html>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.