By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to disable and enable submit button in javascript

P: 2
Hello,
How do I disable a submit button for 2 minutes and then enable it from 10 minutes past from the hour i.e 12:08 to 12:10 disable button and then enable from 12:10 to 12:18 disable from 12:18 to 12:20 and so on around the clock. Can this be done in JavaScript. Thanks for your help.
Jan 19 '18 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,031
I've changed your request from minutes to seconds, but you can change that yourself with the following code

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <body onload="setInterval(myFunction,100)">
  4.  
  5. <p>Click the button to display the minutes of the time right now.</p>
  6.  
  7. <button id="mybutton" onclick="myFunction()">Try it</button>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. function myFunction() {
  13.     var d = new Date();
  14.     var nh = d.getHours();
  15.     var nm = d.getMinutes();
  16.     var ns = d.getSeconds();
  17.     document.getElementById("demo").innerHTML = (nh*100+nm)*100+ns;
  18.     var t = ns;
  19.     document.getElementById("mybutton").innerHTML = t % 10;
  20.     if ((t % 10) >=8 && (t % 10) <10) 
  21.         document.getElementById("mybutton").disabled = true
  22.     else 
  23.         document.getElementById("mybutton").disabled = false
  24. }
  25. </script>
  26.  
  27. </body>
  28. </html>
  29.  
Jan 20 '18 #2

P: 2
Thank you you are a star and you will go far.
Jan 20 '18 #3

P: 5
Thank you great solution.
Feb 1 '18 #4

Post your reply

Sign in to post your reply or Sign up for a free account.