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 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2010
    Location
    Denver
    Posts
    26
    Thanks
    8
    Thanked 0 Times in 0 Posts

    hiding/disabling the submit button based on dropdown selection

    How can I hide/disable the submit button if the name Todd is selected?


    Code:
    <html>
    <head>
    </head>
    <body>
    
    <form name="people">
    <select name="group">
     
     
    <option value="Pick Your Name">Choose</option>
    <option value="Tom">Tom</option>
    <option value="Freddy">Freddy</option>
    <option value="Todd">Todd</option>
    <option value="Fred">Fred</option>
    <option value="William">William</option>
    <option value="Johnson">Johnson</option>
    </select>
    <INPUT TYPE=submit VALUE="submit"> 
    </form>
    </body>
    </html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,565
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Code:
    <select name="group" onchange="if (this.value=='Todd') this.form.DoSubmit.style.display='none';">
    ...
    <input type="submit" name="DoSubmit" value="submit" />
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Rangers (11-09-2010)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,565
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Or (not both...one or the other):
    Code:
    <form name="people" onsubmit="return ( this.form.group.value != 'Todd');" >
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Oct 2010
    Location
    Denver
    Posts
    26
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Can I make this a little harder. What if I select Todd and the submit button is hidden and then click on another name can the submit button reappear?

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,565
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Code:
    <select name="group" 
      onchange="this.form.DoSubmit.style.display = (this.value=='Todd') ? 'none' : 'inline';">
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,565
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    I assume you are playing a trick on a friend?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Oct 2010
    Location
    Denver
    Posts
    26
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Code:
    <select name="group" 
      onchange="this.form.DoSubmit.style.display = (this.value=='Todd') ? 'none' : 'inline';">
    Thanks Old Pedant...

    This is not a trick. I am running a league and getting frustrated when people submit their choices in at the last minute. So I wanted to give each person 3 times where they can hand in their choices late, after that I want to hide their submit button after the deadline has hit.

    Thanks again

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,565
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Not to ask a dumb question, but... Why not simply remove their name from the list, instead of blocking them?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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