Cerca nel supporto

Attenzione alle mail truffa. Mozilla non chiederà mai di chiamare o mandare messaggi a un numero di telefono o di inviare dati personali. Segnalare qualsiasi attività sospetta utilizzando l'opzione “Segnala abuso”.

Learn More

Questa discussione è archiviata. Inserire una nuova richiesta se occorre aiuto.

Since keyCode and key are being deprecated within events like keypress, how do you implement checking for a specific key press?

  • Nessuna risposta
  • 1 ha questo problema
  • 3 visualizzazioni
more options

I am trying to only allow specific key strokes within an input dom element. On the dom element I include onkeypress="someFunction(event)" and within someFunction I get the keyCode as follows: event.keyCode. This fails and so I looked up in the MDN and it states that keyCode is being deprecated. I tried using key in place of keyCode with same result. I am on a Windows 7 machine but this will be released to any device / browser that supports HMTL5. syntax: <input id="txt506PanDrySoilMass" class="uiRequiredField T506Calc T506BlankInput" type="text" style="text-align:center;" maxlength="6" onkeypress='Utilities.WholeNumberOnly(event);'/> Inside the Utilities namespace: WholeNumberOnly: function (event) {

       var newDigit = String.fromCharCode(event.keyCode); <---fails here
       ...
   },

Code works within IE, Edge, Chrome and a few others. What is the best way to implement this within Firefox?

I am trying to only allow specific key strokes within an input dom element. On the dom element I include onkeypress="someFunction(event)" and within someFunction I get the keyCode as follows: event.keyCode. This fails and so I looked up in the MDN and it states that keyCode is being deprecated. I tried using key in place of keyCode with same result. I am on a Windows 7 machine but this will be released to any device / browser that supports HMTL5. syntax: <input id="txt506PanDrySoilMass" class="uiRequiredField T506Calc T506BlankInput" type="text" style="text-align:center;" maxlength="6" onkeypress='Utilities.WholeNumberOnly(event);'/> Inside the Utilities namespace: WholeNumberOnly: function (event) { var newDigit = String.fromCharCode(event.keyCode); <---fails here ... }, Code works within IE, Edge, Chrome and a few others. What is the best way to implement this within Firefox?