View Tutorial Metadata Edit Content Revision History Add to Watchlist Add New Tutorial How to enable or disable an input element with jQuery

How to enable/disable an input element with jQuery

If you want to disable an element with pure HTML then you would add a property called disabled :

<input type="submit" name="submit" id="submit_btn" disabled="disabled" />

but if you want to do this dynamically you can use Javascript.

An example where this is needed : you perform an AJAX request and you don't want the user to be able to do several clicks on the button that triggers the request.

A simple implementation would be .. disable the button before triggering the AJAX request and enable the button after your call successfully ended.

Here is the jQuery code for enabling / disabling the button from the code above :

// Disable button
$("#submit_btn").attr("disabled", true); 
// Enable button
$("#submit_btn").removeAttr("disabled");

Only plain text supported.

Optional

Required - will be kept private

Optional

 
 

Rating: (0+, 0-) In: jQuery