<input type="number" value="5" id="mynumber"> <script> document.getElementById('mynumber').onkeypress = function (e) { if (e.charCode == 45) { this.value = -this.value; //this.value *= -1; return false; } }; </script>