Try preventing the default behaviour if you don’t like the incoming key value:
document.querySelector("input").addEventListener("keypress", function (evt) {
if (evt.which < 48 || evt.which > 57)
{
evt.preventDefault();
}
});
More Related Contents:
- How to read with JavaScript [closed]
- How to store objects in HTML5 localStorage
- Invoking JavaScript code in an iframe from the parent page
- Capture HTML Canvas as gif/jpg/png/pdf?
- Adjust width and height of iframe to fit with content in it
- Disabling browser print options (headers, footers, margins) from page?
- How to get numeric value from a prompt box? [duplicate]
- How to set value of input text using jQuery
- Stop embedded youtube iframe?
- javascript – shuffle HTML list element order
- How to create a sticky navigation bar that becomes fixed to the top after scrolling
- How to open a new window and insert html into it using jQuery?
- Phonegap InAppBrowser display pdf 2.7.0
- Change ‘s option and trigger events with JavaScript
- How to format Vuetify data table date column?
- How do I save and restore a File object in local storage
- How can I retain the scroll position of a scrollable area when pressing back button?
- How to send variables from one file to another in Javascript? [duplicate]
- How does the location of a script tag in a page affect a JavaScript function that is defined in it?
- Dark mode flickers a white background for a millisecond on reload
- How to save canvas animation as gif or webm?
- Can we use the value of localStorage from other domains?
- Resource interpreted as Script but transferred with MIME type text/plain – for local file
- Check if a file exists locally using JavaScript only
- Is there an equivalent of canvas’s toDataURL method for SVG? [closed]
- jQuery DataTables “No Data Available in Table”
- Gaussian Blur onHover Using jQuery
- How to show fullscreen popup window in javascript?
- copying the value of a form’s file input field to another form’s input field
- Bootstrap Dropdown menu is not working