473,657 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to disable and enable submit button in javascript

2 New Member
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 4433
Luuk
1,047 Recognized Expert Top Contributor
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 New Member
Thank you you are a star and you will go far.
Jan 20 '18 #3
RockybBalboa
5 New Member
Thank you great solution.
Feb 1 '18 #4
Sherin
77 New Member
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 Recognized Expert Moderator Expert
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
11273
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 me to do this? <input type="Submit" value="Update"> Any help would be greatly appreciated TIA
4
2005
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 the submit button. When the user clicks submit, the value of the button changes to "Processing..." and the button disables. The cgi to which it is submitting will process the data and render the
2
4939
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
5581
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 postback. I.e. the button does go disabled, but the form does not invoke submit() method. Of course, it does work fine without this property. Clues?
3
13095
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 disable the button in the OnClick event in ASP.Net because then the Click event won't post to the server (because you disabled it). I searched google groups, and there is a solution to this problem, but I didn't think it was clean enough and...
3
3161
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 the submit button once it's been clicked, yet still have the form submit. I can do this in ASP 2.0, however, ASP.Net seems to be adversely affected if you disable the submit button. Here's how I have it set up... The submit button is a...
3
7237
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 data_2a data_2b . . . . . . . . . . . . Checkbox_n data_na data_nb
3
11688
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 onload()......... var SelectedElementId=<%=request.getParameter("selectedId") %> //var selectedPredicateType = <%=request.getParameter("selectedType") %>
2
2880
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 button and Change the text to "Please Wait..." I have the code done, and it sorta works. FireFox3 does not seem to update the page until all JavaScript is done executing, so after the few seconds of nothing happening, then the button is disabled and...
5
11817
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 work based on a data field value. I have created a textbox in a hidden area that contains the stored data value. I have set the beginning value of the submit button to disabled. I want the submit button to be enabled if the value in the textbox is...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.