Execute a JavaScript when an input field is about to lose focus:
When you leave the input field, a function is triggered which transforms the input text to upper case.
<!DOCTYPE html> <html> <body> Enter your name: <input type="text" id="fname" onfocusout="myFunction()"> <script> function myFunction() {//from w w w . j a v a 2 s . co m var x = document.getElementById("fname"); x.value = x.value.toUpperCase(); } </script> </body> </html>
The onfocusout event occurs when an element is about to lose focus.
The onfocusout event is similar to the onblur event.
The onblur event does not bubble.
To find out whether an element or its child loses focus, use the onfocusout event.
To find out whether a child of an element loses focus, use a capturing listener for the onblur event by setting the optional useCapture
parameter of the addEventListener()
method.
The onfocusout event is the opposite of the onfocusin event.
The onfocusout should work as an HTML attribute and by using the addEventListener()
method.
Bubbles: Cancelable: Event type: Supported HTML tags: | Yes No FocusEvent ALL HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|