Check input text field value with if statement - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Check input text field value with if statement

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function guess() {/*w  w  w.j  a v a  2 s.  c o  m*/
    var x = document.getElementById("magic").value;
    var word = "please";
    if (x == word) {
        console.log("You entered the magic word!");
    } else {
        console.log("Please try again!");
    }
}

      </script> 
   </head> 
   <body>
       What is the magic word?
      <br> 
      <input type="text" id="magic" onblur="guess()">  
   </body>
</html>

Related Tutorials