Tag Archives: button

How to Disable a Button with jQuery CodeUnit 25 FEB 2010

Disabling a button on a webpage using jQuery is remarkable simple – just set the selected button’s disabled attribute to true, in other words, make use of a .attr(‘disabled’,true) function call.

This can then obviously be extended to disabling all buttons on a webpage using the following snippet of code:

$('input[type=button]').attr('disabled', true);

Like I said, remarkably simple. (Obviously to enable you simply set the attribute to false again!)

jQuery: Prevent Double Form Submission CodeUnit 25 APR 2009

Coffee CupA very clever little jQuery function here that I’ve gone and lifted from some deep, dark domain of the Web.

Essentially what it does is prevent accidental double form submission (which could for example happen if it appears to the user that nothing is happening after he already pressed on the submit button once), by assigning a function to the submit action of each and every form on a particular page. The function simply disables any image or submit buttons that are bound to that form, thereby preventing a secondary click in one foul swoop.

$("form").each(function()
{
var $that = $(this);
$that.submit(function(){
$that.find("input[type='image'],input[type='submit']").attr("disabled", "true");});
});

Like I said, pretty clever.