Verifying text box content with if statement - Javascript Statement

Javascript examples for Statement:if

Description

Verifying text box content 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 check() {/*from   ww  w .j av a  2 s. c o m*/
    if(document.getElementById("sometext").value == '') {
        console.log('Field is empty');
    }
    else {
        console.log('Field is not empty');
    }
}

      </script> 
   </head> 
   <body> 
      <input type="text" id="sometext" value=""> 
      <input type="button" id="check" onclick="check();" value="Check if empty">  
   </body>
</html>

Related Tutorials