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>
The onchange JavaScript event is triggered when an element is changed and then loses focus. In the context of a textarea , this happens when the content of the textarea is modified and then the textarea loses focus because the user clicks away or presses the tab key.
Events focus/blur The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an input field. In the example below: The blur handler checks if the field has an email entered, and if not – shows an error.
The onfocusout event occurs when an element is about to lose focus. Tip: The onfocusout event is similar to the onblur event. The main difference is that the onblur event does not bubble. Therefore, if you want to find out whether an element or its child loses focus, you should use the onfocusout event.
The focusout event fires when an element is about to lose focus.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With