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

enable/disable submit button

P: 110
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
Share this Question
Share on Google+
5 Replies

Expert Mod 15k+
P: 16,027
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

P: 110
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

Expert Mod 15k+
P: 16,027
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

P: 110
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. }
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">
Nov 13 '08 #5

Expert Mod 15k+
P: 16,027
...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;
Nov 13 '08 #6

Post your reply

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