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
    Aug 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS to disable form submit button?

    I would like to make sure users do not click the submit button on my form more than once.

    Is there some way to do this using Javascript?



    thankx for your input!

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    <form onsubmit="document.getElementById('mysub').disabled=true;">

    <input type="submit" id="mysub">

    </form

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    More than once, per page visit or more than once a day/week/month/year?
    The code above will take care of preventing someone from submitting the form twice per page visit, but it would take a simple page refresh to get around it.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's a useful trick though - it's amazing how many people double-click buttons and hyperlinks, and this can prevent forms from being submitted twice by mistake - with stuff like credit card purchases that can be quite serious.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #5
    New Coder
    Join Date
    Aug 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    once per page visit is fine for a limit.

    i tried implementing the code above but my form just wouldnt submit at all...

    am still working on it.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It will prevent repeated form submition using the "submit" button, but will not help when user presses "enter". I would use cookies for the task - maybe a bit extra work up front, but sure allows for much more flexibility if needed...
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this
    Code:
    <form onsubmit="this.elements['mysub'].disabled=true;return true;">
    
    <input type="submit" name="mysub">
    
    </form>
    Vladdy -- what? onsubmit is fired by any submission except one triggered by the form's submit() method.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are right - brainfart on my part....
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

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