Check value from number Input field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

Check value from number Input field

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <input type="number" max="5" oninput="checkLength(this)"> 
      <script type="text/javascript">
function checkLength(elem) {/*from w w  w . jav a2 s.c  om*/
  if (elem.value > 5) {
    console.log('Max value is 5')
    elem.value = '';
  }
}

      </script>  
   </body>
</html>

Related Tutorials