Hi Alan,
This should do the trick (tested in Firebug): var countdown; var timer = 5; if ( $('#form-submit').val() == 'Submit') { countdown = setInterval(function() { if (timer > 0) { $('#form-submit').val(timer); timer = timer -1; } else { $('#form-submit').val('Submit'); clearInterval(countdown); return; } }, 1000); } --Karl _________________ Karl Swedberg www.englishrules.com www.learningjquery.com On Mar 8, 2008, at 5:56 AM, alan wrote:
Hi, I am trying to get a submit button, once clicked, to disable itself, countdown, then reenable itself to prevent a form from being submitted too rapidly. I've figured it out, but in a way that I think is pretty messy and not very scalable, I'm wondering if I am going about this the wrong way and if there is a more efficient way to code something like this? --- $("#form-submit").attr("value",5).animate({opacity: 1.0}, 1000, function() { $("#form-submit").attr("value",4).animate({opacity: 1.0}, 1000, function() { $("#form-submit").attr("value",3).animate({opacity: 1.0}, 1000, function() { $("#form-submit").attr("value",2).animate({opacity: 1.0}, 1000, function() { $("#form-submit").attr("value",1).animate({opacity: 1.0}, 1000, function(){ $("#form-submit").attr("disabled",false); $("#form-submit").attr("value","Submit"); }) }) }) }) }); --- Thanks a lot! Alan