Horje

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
<!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() {
  let x = document.getElementById("fname");
  x.value = x.value.toUpperCase();
}
</script>

</body>
</html>

Output should be:

How to validate an input field when the user leaves it




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Form Events Attribute
Uploaded by:
Admin