Horje
HTML onblur Attribute

Definition and Usage

The onblur attribute fires the moment that the element loses focus.

Onblur is most often used with form validation code (e.g. when the user leaves a form field).

Tip: The onblur attribute is the opposite of the onfocus attribute.


Applies to

The onblur attribute is part of the Event Attributes, and can be used on any HTML elements.

Elements Event
All HTML elements onblur

Browser Support


How to Validate an input field when the user leaves it

When you leave the input field, a function is triggered which transforms the input text to upper case.
index.html
Example: HTML
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() {
  let x = document.getElementById("fname");
  x.value = x.value.toUpperCase();
}
</script>

Output should be:

How to Validate an input field when the user leaves it




html onblur attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference