Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post

    disable the "SUBMIT" button until a couple of buttons are pressed first

    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

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,695
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    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.

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    sorry VIPStephan, thank you for that

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,695
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,020
    Thanks
    15
    Thanked 239 Times in 239 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #8
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    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

  • #9
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    The basic code for enable/disable is:

    Code:
    <form action="" method="post">
    <input name="rad" type="radio" value="Yes" onclick="this.form['sub'].disabled=false"> YES
    <br>
    <input name="rad" type="radio" value="No" onclick="this.form['sub'].disabled=true"> NO
    <br>
    <br>
    <input type="submit" name="sub" value="Submit" disabled>
    </form>
    This is for radio buttons but the same code can be used for buttons.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #10
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    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

    thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •