Javascript examples for DOM HTML Element:Input Number
Validate if html input field is a number within range
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* w w w . j a v a2s . c o m*/ document.getElementById('test').onchange = isNumber; function isNumber(){ var val = this.value; var aNumber = !isNaN(val); var aNumberNotOverOneHundred = (Math.abs(parseFloat(val, 10)) <= 100); console.log((aNumber && aNumberNotOverOneHundred)?"Yarp":"Narp"); } } </script> </head> <body> <input id="test" type="text"> </body> </html>