Submit Button enable and disable by input field length value - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Submit Button enable and disable by input field length value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*  ww  w.j av  a  2s .  c  o  m*/
var btn=document.getElementById("btn");
var phone=document.getElementById("phone");
phone.onkeyup=function(){
   btn.disabled=!(phone.value.length===10);
};
    }

      </script> 
   </head> 
   <body> 
      <input id="phone" type="text"> 
      <button id="btn" disabled>Send</button>  
   </body>
</html>

Related Tutorials