HTML onblur attribute

HTML onblur attribute: The HTML onblur attribute will fire at that moment when the element loses focus. This attribute is mostly used in Form validation code. This attribute is the opposite of the onfocus attribute.

HTML onblur attribute

This attribute can be applied to all the elements in HTML. And it is a part of the event attribute.

Syntax: <element onblur=”script”>



Attribute Value

This attribute is used for any HTML elements. The script run when onblur attribute called.

Browser Support

This attribute was supported by different browsers.

  • Chrome
  • Firefox
  • Internet Explorer
  • Safari
  • Opera

Example:

<!DOCTYPE html>
<html>
<body>

Enter your name: <input type="text" name="fname" id="fname" onblur="myFunction()">

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

<script>
function myFunction() {
  var x = document.getElementById("fname");
  x.value = x.value.toUpperCase();
}
</script>

</body>
</html>

Output:

html onblur attribute