Execute a script when the element loses focus in HTML?


Use the onblur attribute execute a script when the element loses focus in HTML. You can try to run the following code to implement onblur attribute −

Example

<!DOCTYPE html>
<html>
   <body>
      <p>Type text below!</p>

      Country: <input type = "text" name = "myid" id = "myid" onblur = "display()">

      <script>
         function display() {
            var str = document.getElementById("myid");
            str.value = str.value.toUpperCase();
         }
      </script>

   </body>
</html>

Updated on: 03-Mar-2020

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements