Javascript DOM onblur Event

Introduction

Execute a JavaScript when a user leaves an input field:

When you leave the input field, a function is triggered which transforms the input text to upper case.

View in separate window

<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" id="fname" onblur="myFunction()">
<script>
function myFunction() {/*www . j  a  v a  2  s .c om*/
  var x = document.getElementById("fname");
  x.value = x.value.toUpperCase();
}
</script>

</body>
</html>

The onblur event occurs when an object loses focus.

The onblur event is the opposite of the onfocus event.

The onblur event does not bubble.

To find out whether an element or its child loses focus, use the onfocusout event.

Or you can use the optional useCapture parameter of the addEventListener() method for the onblur event.

Bubbles:
Cancelable:
Event type:
Supported HTML tags:












No
No
FocusEvent
ALL HTML elements,
EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related