Submit Button Enabling

"Enabling" you ask? Yes. We all know how to disable the submit upon form submission and the reasons for doing so, but what about re-enabling the submit button after an allotted amount of time. After all, what if the user presses the "stop" button immediately after submitting the form? They'd be screwed. Why not re-enable the submit button after an allotted amount of time so that the user may re-submit?

The MooTools JavaScript

window.addEvent('domready',function() {
		var subber = $('submit');
		subber.addEvent('click',function() {
			subber.set('value','Submitting...').disabled = true;
			(function() { subber.disabled = false; subber.set('value','Resubmit'); }).delay(10000); // how much time?  10 seconds
		});
	});

Of course, this isn't ideal in all situations. It is, however, a nice touch if your system can accommodate for it.

Update: Upon submission, the button's message changes to "submitting..." and once enabled, the message changes to "Resubmit." Thank you to Facundo Corradini for the suggestion!


Comments

  1. Lim Chee Aun

    Neat idea on the timeout. Though you shouldn’t run the same selector more than once, and should have cache the selector results for example, by writing (MooTools style):

    var submit = $(‘submit’);
    /* … */
    submit.disabled = true;

  2. david

    @Lim Chee Aun: You always get me! Updated.

  3. cevarief

    I’d prefer to turn the submit button to cancel button after 5 or 10 sec, so user still can choose cancel or wait. Nice touch david.

  4. Clinton Montague

    That’s thinking outside the box – I like it!

  5. Ahmad Alfy

    That was really good!

  6. Brenelz

    Neat little script David. You definitely don’t want the submit button to stay disabled if the form doesn’t finish submitting.

  7. Facundo Corradini

    That was a really useful script.

    I think it would be better if it give some feedback to the user, e.g. changing the button label to “submitting” or something like that.

    Otherwise, it can be really confusing to some users.

  8. david

    Great suggestion Facundo Corradini! Updated.

  9. Qasim Alyas

    Another touch you can possibly add is to change the cursor to default when in ‘Submitting’ state. It sort of gives the wrong impression that you can still click the button when in fact it’s disabled. Nice script though.

  10. Brian Boyce

    Hey David,

    Nice thoughts on this script. I modified it slightly to use for my CMS, and (as usual) it works great in Firefox. In IE and Safari, however, it seems to cancel the actual form-sending. Here’s my code for use with multiple submit buttons; if anyone sees the problem(s) with it, feel free to use/fix it.

    I triggered it by adding a “submit” class to the submits that would use it. Trying to have it find the ‘submit’ object would give errors when there were more than one submit button on the page.

    $$(‘.submit’).each(function(o, x) {
    o.addEvent(‘click’,function() {
    var old = o.value;
    o.set(‘value’,'Submitting…’).disabled = true;
    (function() { o.disabled = false; o.set(‘value’,old); }).delay(10000); // how much time? 10 seconds
    });
    });

  11. vicmx

    Not works with Mootools 1.11 :S

  12. zephiro

    Nice trick but does’nt prevent people from continiously press the enter key.

  13. zephiro

    … I finally saw “Prevent Early Form Submission by Hijacking the Enter Key” article that fits well for what I noticed just before.

    Another solution may be a combination of this :

    $(‘myform’).addEvent(‘submit’, function(e){
    e.stop();
    $(‘mytextinput’).addEvent(‘keydown’, function(e){
    if(e.key == ‘enter’) {
    e.stop();
    }
    });
    //my code here …

    //and at the end of the code …
    $(‘identifiant’).removeEvents(‘keydown’);
    });

    By the way, why people never use the submit event on form ?
    I find it more usefull than the click event on submit button because it also trigger the form on enter key press.

  14. Joel

    I just added this to an app, but it doesn’t seem to work in IE6 and 7.
    When the submit button is disabled the form submission in canceled. Or am I missing something?

    In order to get it work I need to stop the event and then programatic submit the form. See this page for example: http://dl.dropbox.com/u/3049118/lab/disable-submit-test.html

  15. absolutely shanxi black

    China TwoWin Stone fabricate the absolute black granite,slate,shanxi black granite,granite monuments,granite memorial,granite headstones,stone monument,grave markers,animal memorials,granite Tombstone,memorial stones

  16. granite countertop

    China TwoWin Stone Company is the granite manufacturers,factory and exporter in China,specialized in granite counter tops and marble vanity tops,granite tiles,granite and marble table tops,granite slabs and bath tub surround,Vanities and Sinks,granite stairs and marble mosaic tiles.

  17. WDcore

    In this post, we are sharing some excellent and free feather Photoshop brushes for you to download. Photoshop brushes always come in handy no matter what type of artwork you are creating. For this session, we are compiling an ultimate collection of some high quality feather brushes that can very easily be incorporated in Adobe Photoshop and provide realistic results.
    You can use these brush sets for your next projects. We have gathered them Deviant Art and make sure that all the brushes are of high resolution so that they can provide sensuous and delicate results. Once again, it’s our pleasure to share with you what we have gathered from all over the web. We hope that this collection will help you with your masterpieces. Click through and feel free to download. Do let us know what you feel about this round up.

  18. WDcore

    Vintage look or vintage style has been quite trendy in the recent years, and this is the reason why designers also are trying to incorporate a vintage look in their artworks. One of the easiest ways to incorporate certain style in your design is by using texture. This is because textures are among those design resources that help you create great designs without much effort.
    Here we present a compilation of some amazing and high quality vintage textures for you that you can download and use for free. With the help of such textures, you can effortlessly draw attention to your images to better portray the vintage feel that you are trying to get. Although all the textures presented below are free to use but we would appreciate if you read the terms and conditions before using them for commercial purposes.

  19. WDcore

    In this round up, we are showcasing a collection of some amazing and breathtaking still life digital paintings that will surely inspire you and will take your breath away. Since the majority of us in this design arena constantly look for great and inspiring work that we can share, you may find these digital painting pieces as they have jumped out from the webs and demanding to be featured.
    So many extraordinary paintings resonant of the great still lives of the previous days. These digital paintings hold a wealth of inspiration just waiting to be tapped. We hope that you like this collection and will find this inspirational for you. You can always share your opinion with us via comment box below and let us know if we have missed one of your favorite digital painting.

  20. Mark Andrew

    Numbering PDF files is the simplest and shortest method to arrange your PDF pages in order and for this process our company has launched PDF Bates Numberer software for numbering PDF files


Be Heard!

Share your thoughts without being a jerk! And wrap your code in <code> tags, f00!

Name*:
Email*:
Website: