views:

28

answers:

1

I have a simple check ( .val() == "" ) with jQuery if textarea is empty or not before submitting.. it works, but it counts whitespaces.

How can I ignore white spaces in this check?

// Post guestbook; Check on frontend before submitting
function postGuestbook() {
    if ($('.post-form textarea').val() == "") 
    {
        $('div.message.error').show();
        return false
    }
    else {
        $('.post-form input[type="submit"]').attr('disabled', 'disabled');
        return true;
    }
}
+2  A: 
...
if ($.trim($('.post-form textarea').val()) == "") {
    ... 

http://api.jquery.com/jQuery.trim/

karim79