Execute a script when the element loses focus in HTML?

HTMLWeb DevelopmentFront End Technology

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>
raja
Published on 14-Mar-2018 15:03:14
Advertisements