JQUERY cakePHP – Enabling submit button if text entered
Tuesday, September 8, 2009 23:19Posted in category cakePHP Interview Questions
No Comments
jQuery code snippet:
$('#username').keyup(function() {
if ($('#username').val() != '') {
$('#submit').removeAttr('disabled');
} else {
$('#submit').attr('disabled', 'disabled');
}
});
It ensures that the submit button is only enabled if the “username” input field is not empty (you can see such a behavior on twitter for example).
However, the snippet from above can be rewritten in a shorter and more elegant way:
$('#username').keyup(function() {
$('#submit').attr('disabled', !$('#username').val());
});
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.


