473,394 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to disable and enable submit button in javascript

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
5 4424
Luuk
1,047 Expert 1GB
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
Dennyh
2
Thank you you are a star and you will go far.
Jan 20 '18 #3
Thank you great solution.
Feb 1 '18 #4
Sherin
77 64KB
The Code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title>Enable/Disable Submit Button based on Multiple Textbox values</title>
  4. </head>
  5. <body>    
  6.     <p>Enter some values in the text to Enable the Submit button!</p>
  7.  
  8.     <p>Name: <input type="text" id="name" placeholder="Enter your name" 
  9.         onchange="manage(this)" /></p>
  10.     Designation: <input type="text" id="desig" placeholder="Enter designation" 
  11.         onchange="manage(this)" />
  12.  
  13.     <input type="submit" id="submit" disabled />
  14. </body>
  15.  
  16. <script>
  17.     function manage(txt) {
  18.         var bt = document.getElementById('submit');
  19.         var ele = document.getElementsByTagName('input'); 
  20.  
  21.         // LOOP THROUGH EACH ELEMENT.
  22.         for (i = 0; i < ele.length; i++) {
  23.  
  24.             // CHECK THE ELEMENT TYPE.
  25.             if (ele[i].type == 'text' && ele[i].value == '') {
  26.                 bt.disabled = true;    // Disable the button.
  27.                 return false;
  28.             }
  29.             else {
  30.                 bt.disabled = false;   // Enable the button.
  31.             }
  32.         }
  33.     }    
  34. </script>
  35. </html>
Mar 5 '20 #5
gits
5,390 Expert Mod 4TB
The Code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title>Enable/Disable Submit Button based on Multiple Textbox values</title>
  4. </head>
  5. <body>    
  6.     <p>Enter some values in the text to Enable the Submit button!</p>
  7.  
  8.     <p>Name: <input type="text" id="name" placeholder="Enter your name" 
  9.         onchange="manage(this)" /></p>
  10.     Designation: <input type="text" id="desig" placeholder="Enter designation" 
  11.         onchange="manage(this)" />
  12.  
  13.     <input type="submit" id="submit" disabled />
  14. </body>
  15.  
  16. <script>
  17.     function manage(txt) {
  18.         var bt = document.getElementById('submit');
  19.         var ele = document.getElementsByTagName('input'); 
  20.  
  21.         // LOOP THROUGH EACH ELEMENT.
  22.         for (i = 0; i < ele.length; i++) {
  23.  
  24.             // CHECK THE ELEMENT TYPE.
  25.             if (ele[i].type == 'text' && ele[i].value == '') {
  26.                 bt.disabled = true;    // Disable the button.
  27.                 return false;
  28.             }
  29.             else {
  30.                 bt.disabled = false;   // Enable the button.
  31.             }
  32.         }
  33.     }    
  34. </script>
  35. </html>
ok - since 'the code' is constantly posted regardless of being not useful in this context (since its not related to the OP's requirements) lets use it as an example of how not to write Javascript code (even for the 'selfchosen' example the poster decided to throw out code for):

1. function has a meaningless name
2. function gets a parameter passed that is never used
3. the variable i is an implicit global
4. wrong inline comment
5. return value not used but return misused to break out of the loop
6. loop is unnecessarily evaluating length in each iteration
7. element lookup in loop happens twice instead of 1 time only per iteration
Mar 5 '20 #6

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

Similar topics

5
by: Jimbo | last post by:
I am trying to right a script so that the "submit button" only appears when certain criteria has been met. I have tried putting it in an IF statement, without any luck. Maybe a function would allow...
4
by: Frank Way | last post by:
Hi all, I've googled this one to death, and still can't find an answer. Not sure I'm asking the right question, but here goes: Have a form with an onSubmit that has some javscript to disable...
2
by: Mel | last post by:
i want to diable all submit_buttons untill all my form elements are populated. how can i do that ? thanks
4
by: Dmitry Korolyov [MVP] | last post by:
When we use btnSubmit.Attributes = "javascript: this.disabled=true;" to make the button disabled and prevent users from clicking it again while form data still posting, there is no longer...
3
by: Mark | last post by:
This is a solution... Often users want to keep clicking "submit" when they are waiting for server processing. Most apps these days like to disable the submit button to prevent this. You can't just...
3
by: Jeff | last post by:
I have a payment form with a submit button. A large percentage of users double-click the submit button thus submitting their payment information twice. I would like to use javascript to disable...
3
by: connieyongg | last post by:
hi, Lets consider if i have to display my data dynamically using ASP ( the no of data to be displayed is an unknown), My data will be in this format Checkbox_1 data_1a data_1b Checkbox_2...
3
by: javafool | last post by:
Hi, in my case i want to disable the button while clicking onload() in my jsp page.............but i can't do that..........please help me out......... Ex: this is my...
2
by: labmonkey111 | last post by:
I have a form that takes several seconds to run the javascript needed to prepare the form for PHP (selecting all items in a Select Multiple). Since it takes so long, I want to disable the Submit...
5
by: andersond | last post by:
I need to enable or disable a submit button based on the value of a data field stored in a database. I have found working examples of how to enable or disable based on a checkbox; but, I need it to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.