-1

I tried to create an date type input field that would not take key value from keyboard. I used

<input type="date" (keypress)="false"/> 

This keypress event working on Chrome browser

but not working on Mozilla Firefox.

I tried to create an date type input field that would not take key value. I used

<input type="date" (keypress)="false"/> 

This is working on Chrome browser

but ** keypress event not working on Mozilla Firefox**.

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Does this answer your question? [How do I make a text input non-editable?](https://stackoverflow.com/questions/3676127/how-do-i-make-a-text-input-non-editable) – tevemadar Jan 19 '23 at 08:15
  • And why? That's bad UX. – CherryDT Jan 19 '23 at 08:18
  • 2
    What about use `keydown` or `keyup`? ([keypress](https://developer.mozilla.org/en-US/docs/Web/API/Element/keypress_event) is deprecated) – Eliseo Jan 19 '23 at 08:45
  • I agree `keydown`/`keyup` could be a replacement for `keypress` but I would suggest `input` event instead as long as you don't need to `preventDefault()` any keyDown in case they don't match a condition. – Diego D Jan 19 '23 at 09:10
  • I tried all this, but not working!! – Sourav Hasan Jan 22 '23 at 03:41

1 Answers1

-2

function myFunction() {
  alert("You pressed a key inside the input field");
}
<input type="text" onkeypress="myFunction()">