473,385 Members | 1,555 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,385 software developers and data experts.

enable/disable submit button

110 100+
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 "vehiclesAccurate"; 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 vehiclesAccurate="YES"?
Nov 12 '08 #1
5 11796
acoder
16,027 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
...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.getElementById() 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
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
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...
1
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...
14
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...
6
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...
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...
1
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...
10
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.