EnexoOnoma
EnexoOnoma

Reputation: 8836

Easy modification on jQuery code that checks if textboxes are empty. Need to check for textarea also

The following script enables the submit button if a form if is filled up. However I have a textarea

<textarea id="description" tabindex="15" style="width:500px;" name="description" cols="80" rows="10">

and I can not know how to add it for checking. If I type in all textboxes and leave the textarea empty, it will be submitted.

$(document).ready(function () {
    $('form').delegate('input:text, input:checkbox', 'blur keyup click change', function () {
        if(($('form input:text').filter(function(){ return $.trim(this.value) == ''; }).length > 0))
        {
          $('#btnUpdate').attr("disabled", true);
        }
      else {
            $('#btnUpdate').removeAttr("disabled");
      }
    });
});

Thank you

Upvotes: 0

Views: 230

Answers (2)

bfavaretto
bfavaretto

Reputation: 71918

Try changing this:

$('form').delegate('input:text, input:checkbox', // rest of line

to

$('form').delegate('input:text, input:checkbox, textarea',

EDIT

The code should be:

$(document).ready(function () {
    $('form').delegate('input:text, input:checkbox, textarea', 'blur keyup click change', function () {
        if(($('form input:text, form textarea').filter(function(){ return $.trim(this.value) == ''; }).length > 0)) {
            $('#btnUpdate').attr("disabled", true);
        } else {
            $('#btnUpdate').removeAttr("disabled");
        }
    });
});

Upvotes: 1

Kevin Pei
Kevin Pei

Reputation: 5872

$(document).ready(function () {
    $('form').delegate('input:text, input:checkbox', 'textarea', 'blur keyup click change', function () {
        if(($('form input:text').filter(function(){ return $.trim(this.value) == ''; }).length > 0&&$('textarea').val()!==""&&$('textarea').val()!==null))
        {
          $('#btnUpdate').attr("disabled", true);
        }
      else {
            $('#btnUpdate').removeAttr("disabled");
      }
    });
});

Upvotes: 0

Related Questions