Mike Vierwind
Mike Vierwind

Reputation: 7009

Live checking value of textarea

I have a textarea that have a id upload-message. And this jvavscript:

 // step-2 happens in the browser dialog
            $('#upload-message').change(function() {
                $('.step-3').removeClass('error');
                $('.details').removeClass('error');
            });

But how can i check this live? Now, i type in the upload message textarea. And go out of the textarea. Than the jquery function is fired. But how can i do this live?

Thanks

Upvotes: 1

Views: 187

Answers (2)

maxedison
maxedison

Reputation: 17553

Simply bind some code to the keyup event:

$('#upload-message').keyup(function(){
    //this code fires every time the user releases a key
    $('.step-3').removeClass('error');
    $('.details').removeClass('error');
});

Upvotes: 1

Joseph Silber
Joseph Silber

Reputation: 219920

With .keyup:

$('#upload-message').keyup(function() {
    $('.step-3, .details').removeClass('error');
});

However, this'll keep on running for every keypress, which in the case you provided does not make sense.

You should rather bind it once with one:

$('#upload-message').one('keyup', function() {
    $('.step-3, .details').removeClass('error');
});

...so that this event will only fire once.

Upvotes: 3

Related Questions