473,659 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enable/disable submit button

110 New Member
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 "YES" and to remain disabled if the value is "NO". The textbox name is "vehiclesAccura te"; and, the name of the submit button is "B1" and the id is "b1".

The submit button is now disabled. What script code will I need to make it enabled if the value of vehiclesAccurat e="YES"?
Nov 12 '08 #1
5 11817
acoder
16,027 Recognized Expert Moderator MVP
You can enable a submit button with JavaScript by setting its disabled property to false, but the question is why would you want to in this case, when you can just use the server-side code. During page load, if the server-side code is setting the hidden field, it can also enable/disable the submit button based on that value.
Nov 13 '08 #2
andersond
110 New Member
How do you enable/disable a submit button with server-side code? If it's too much trouble to enable or disable with javascript I could just make it visible or hidden; but, I would rather disable or enable so the user can see that there is a submit button present.

The default state is disabled. If they have indicated that a certain field value (a VIN number on a tractor) is accurate on a previous page I want to enable the submit button so they can continue. Otherwise I want them to go back and verify that it is accurate. They have the option of putting their submission on hold and coming back at any time in the next 30 days to enter accurate information and verify its accuracy.
Nov 13 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
As I said, you can enable/disable with JavaScript and it's not much trouble at all.

To disable using server-side code, use an if statement, e.g.
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" ... <?php if (/* condition not met */) echo "disabled='disabled'" ?>">
(example for PHP, change for whichever language you're using).
Nov 13 '08 #4
andersond
110 New Member
I appreciate your expertise in php but I really need you to answer my question. This code does not work. What changes can I make to get this to work using javascript?

Expand|Select|Wrap|Line Numbers
  1. function init(){
  2.     if(document.all.VehiclesAccurate.value=="YES" &&
  3.                    document.all.DriversAccurate=="YES"){
  4.     document.all.b1.disabled=false;
  5.                 } else {
  6.                 document.all.b1.disabled=true;
  7.     document.getElementById('tableVIN_DLmsg').swapNode
  8.                 (document.getElementById('swapTable2'));
  9.     document.getElementById("tableVIN_DLmsg").style.visibility="visible";
  10.         document.getElementById("swapTable2").style.visibility="hidden";
  11. }
  12. }
  13.  
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" value="Request to BIND" name="B1" id="b1" disabled="disabled" style="font-family: Tahoma; font-size: 8pt; font-weight: bold" tabindex="1">
  2.  
Nov 13 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
...and I've been telling you that you can do it in JavaScript, but it'd make more sense on the server-side. However, if you insist...

document.all is non-cross-browser/non-standard. Use document.getEle mentById() instead:
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById("VehiclesAccurate").value=="YES" &&
  2.                    document.getElementById("DriversAccurate").value=="YES") {
  3.     document.getElementById("b1").disabled=false;
  4.  
Nov 13 '08 #6

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

Similar topics

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
0
1827
by: Big John | last post by:
I have not been able to successfully code a toggle button to enable /disable a record filter on a form.... I have been able to put seperate a button that will enable a record filter but cannot get a button to disable the filter, ... would like to make it a toggle button that does it in "on /Off" fashion but do not have expertise .... can this be done ..??? ... Data for selection is determined by "current member = T of F" cheers
1
602
by: Suni | last post by:
Hi everybody, But what I am trying to do is like, there are 2 forms, and if I click on the button in form1, it'll open up form2 and disable the button in form1. Then when I click on the button in form2, it will close form2, and then enable the button in form1. Could you please give me some hints about this? Thanks, Suni
14
7181
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by adding a java script for the button. But, useless.. Please help! Thank you
6
4039
by: GD | last post by:
Hi, I wonder how to disable the "submit" behavior of a button. What I want is to assign values to dynamically added user controls without page postback. Problem: dynamically created control can not be accessed because the button click trigers page postback(see sample code). When the button is clicked, an error occurs: "System.NullReferenceException: Object reference not set to an instance of an object." Please help. Thanks.
3
3162
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...
1
3881
by: javasachin | last post by:
Hello, I want to enable Struts2 Submit button <s:submit> in the client side using JavaScript based on the user inputs in some other controls (textboxes). If user is not entering any values in the text boxes, I want to disable the <s:submit> and if user enters any text, then I want to enable this <s;submit. button. Can you kindly tell me how to do this??? Thanks in advance. Regards, Sachin
10
9090
by: sowmyati | last post by:
HI All, I am new to javascript. I have snippet wherein i am giving a brief note on what i am trying to do. In the below have a variable by name stuff. trying to reset the page. Part of the code which does reset is attached below. there is a reset button which will reset the connection and it takes two min for data loading during which the reset button has to be disabled and later after two mins it should enable the button for the user. ...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
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
7356
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...
0
5649
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.