View Full Version : disable the "SUBMIT" button until a couple of buttons are pressed first

08-06-2012, 08:28 PM
hey people, i have a small problem for an order form. I have several sections within an order form. each section contains various products which have a value to it. A customer, when placing order will select products within a section or in different sections. each section will have a "total" button within. when clicked on, it will show the sub total of products within that particular section.

At the end of the form there is a button for the grand total, which will show the total cost of products from various sections that were selected.

what i want is the submit button to be disabled until.......

1) one or more (14 subtotal buttons) are clicked, so that the customer can view the subtotal

2)the grand total button is clicked so that the customer knows the total cost of the order.

would really appreciate it if someone could help

thank you

08-06-2012, 08:44 PM
Almost none of this functionality can be done with HTML, let alone CSS. I suppose your application is done with PHP? So I’m gonna move this to the PHP forum. This can also be done with JavaScript but JS shouldn’t be the primary solution, it’s just for enhancement. Therefore the first stop is the PHP forum.

08-06-2012, 09:30 PM
sorry VIPStephan, thank you for that

08-06-2012, 11:57 PM
If you want it to be done before submission (eg, page doesn't have to reload), then it has to be done with Javascript. As PHP is server side, you'd have to submit the form and then process it to figure out if the appropriate stuff is enacted without Javascript.

08-07-2012, 12:43 AM
Yeah, that’s the point I was making. PHP functionality has to come first before any JS enhancements are done. One shouldn’t rely on JS alone.

08-07-2012, 05:35 AM
Why not have javscript do it up right, write a javascript function that gets all the input values for the form, produces a modal window that shows all the subtotals and total, and has two buttons on it, one for NO and one for YES, if the totals are right, and the one for YES also enables the submit button. You can give a class to the form inputs if javascript has a problem with the form names.

08-07-2012, 03:51 PM
I have to say though, I don't quite believe that PHP has to come first. Specially these days, I feel a Javascript solution as the primary is perfectly acceptable, AS LONG AS you have redundancies built into PHP to avoid breaking your system.

Now, I don't think that should always be true. If you don't NEED javascript to do whatever you want, then build the PHP first and use the JS to make it pretty. But if what you want to do cannot be achieved with PHP alone, I think using JS as the primary solution, and PHP as the backup is fine, given you'd end up limiting yourself a lot with PHP as the primary.

For example, I have a website on which players can build a grid map. I could have written A LOT of PHP to make a grid map work without JS, and then written the same amount of JS to do it. And in the end, people using it with the PHP would have just gotten frustrated, it'd be a lot more bug prone, etc. Instead, when JS isn't active, my system tells them the site won't function without it.

In this case, I think building a JS solution with a PHP redundancy is the right choice, specially as neither will be complicated. I don't think we should stay locked in to the idea that the site should ALWAYS work without JS and should just be prettier with it.

08-07-2012, 06:12 PM
yes keleth i want it to be done before submission, i personally dont think its anything to do with php becos all i want is the submit button to be disabled until other buttons are clicked? but i may be wrong

08-07-2012, 06:54 PM
The basic code for enable/disable is:

<form action="" method="post">
<input name="rad" type="radio" value="Yes" onclick="this.form['sub'].disabled=false"> YES
<input name="rad" type="radio" value="No" onclick="this.form['sub'].disabled=true"> NO
<input type="submit" name="sub" value="Submit" disabled>

This is for radio buttons but the same code can be used for buttons.

08-08-2012, 11:13 AM
thnx andrew, theres several buttons on this button, is there any way of linking these buttons to the submit button, so that a customer has to click on one or buttons before clicking the submit button


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum