Greying out submit button untill user give input : jQuery snippets #1

Scenario
/*
The submit button needs to wait till the user enter something into the input box. This is useful in most cases, where null injection can cause trouble
*/

Challenge
/*
* The button should initially become disabled
* It should become alright after the user enters some stuff
* It should go back to disabled state once the user have cleared everything out
*/

Code

$( ‘#buttonClick’ ).prop( ‘disabled’, true );
$(‘.input’).on(‘input’, function() {
$(this).next().prop(‘disabled’, $(this).val().length < 1);
});

Hope it helps someone.

Related links:-
[1] http://jsfiddle.net/4gxuU/
[2] https://gerrit.wikimedia.org/r/#/c/120487/

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s