Detect input value length on focus - Javascript jQuery

Javascript examples for jQuery:Form Input

Description

Detect input value length on focus

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/*from   ww w.j  a v a2s . co m*/
$('input').keyup(function(){
  if ( $(this).val().length > 0 ) {
    $(this).css('color', 'blue');
  }
  else {
    $(this).css('color', 'red');
  }
});
    });

      </script> 
   </head> 
   <body> 
      <input type="text">  
   </body>
</html>

Related Tutorials