Reputation: 25928
In HTML or Javascript is it possible to detect when a textarea looses focus?
I have a text area & on loosing focus I want to read the data in a textarea & check if its valid.
Maybe...
<textarea onloosefocus="myFunct();">
</textarea>
// or
var isTyping = false;
function onKeyUp( event )
{
setTimeout( function()
{
isTyping = false;
}, 100);
setTimeout( function()
{
if (!isTyping)
validateTextArea();
}, 500);
}
function onKeyDown( event )
{
isTyping = true;
}
<textarea onkeydown="onKeyDown(e);" onkeyup="onKeyUp(e);">
</textarea>
Upvotes: 11
Views: 21351
Reputation: 318498
The event you are looking for is the blur
event, available through the onblur
attribute:
<textarea onblur="myFunct();"></textarea>
However, it's much better if you attach events properly, e.g. through jQuery:
$('#id_of_your_textarea').on('blur', function(e) {
// your code here
});
Upvotes: 18
Reputation: 25763
You can also use the onblur
attribute for the textarea if you don't have access to jquery
Upvotes: 3