If the current time is between 10 AM and 7 PM, the button is enabled; otherwise, it is disabled JAVASCRIPT code

 You can achieve this using JavaScript to disable or enable the button based on the current time. Below is an example code snippet to accomplish this:


<!DOCTYPE html>

<html>

<head>

  <title>Time-based Button</title>

  <script>

    function checkTime() {

      var now = new Date();

      var hours = now.getHours();


      // Check if the current time is between 10 AM and 7 PM

      if (hours >= 10 && hours < 19) {

        document.getElementById("submitBtn").disabled = false; // Enable the button

      } else {

        document.getElementById("submitBtn").disabled = true; // Disable the button

      }

    }


    // Call checkTime initially to set the initial state of the button

    checkTime();


    // Call checkTime every minute to keep updating the button state

    setInterval(checkTime, 60000); // Update every minute

  </script>

</head>

<body>

  <button id="submitBtn">Submit</button>

</body>

</html>


This code checks the current time every minute using setInterval() and disables or enables the button accordingly. If the current time is between 10 AM and 7 PM, the button is enabled; otherwise, it is disabled.

Comments

Popular posts from this blog

Unleashing the PHP Developer in You: How to Crack Any Interview with Confidence