anand
anand

Reputation: 1751

How to know that some text is entered as well as cursor has come out of textbox?

I want to know if there is any event or way to know that some text has been entered into the textarea and also the user has come of the textarea, so that i can invoke some text like "success".

For the some values in the textarea i think we can do through val() function. But how to know that user has come out of the Textarea

My code is like:

<input type="textarea" id="link1"></textarea>

Upvotes: 0

Views: 80

Answers (4)

Vicky
Vicky

Reputation: 704

if (!$("#link1").val()) {
    // textarea is empty
}

You can also use $.trim to make sure the element doesn't contain only white-space:

if (!$.trim($("#link1").val())) {
    // textarea is empty or contains only white-space
}

and for detecting when user comes out of textarea

$('#link1').focusout(function() {
    alert(this.id + " focus out");
});

Upvotes: 2

pnkz
pnkz

Reputation: 336

Using onKeyPress it can be detected weather some text has been entered and onBlur it can be detected weather the user has come of the textarea

<input type="textarea" id="link1" onBlur = blured() onKeyPress = pressed()></textarea>

Upvotes: 1

monkeyinsight
monkeyinsight

Reputation: 4859

textarea should be like

<textarea id="link1"></textarea>

events you are searching are onkeyup, onfocus and onblur

Upvotes: 1

Mark Rijsmus
Mark Rijsmus

Reputation: 627

Try to catch the onblur event and then check the value.length to see if there is a value added to the textbox.

Upvotes: 1

Related Questions