I want to add some events to some input['text'], I would like to make it clean and add them from javascript . But I can't get them to work, how should I do it? This is how I tried to make it work
function soloNumeros(e){
var key = window.Event ? e.which : e.keyCode
return (key >= 48 && key <= 57)
}
var prueba = form.querySelectorAll('input[type=text]')[4];
prueba.addEventListener('keypress', soloNumeros(e));
```
If you want to cancel the default behavior of a key, just assign a range in the event where it is not clickable:
I think you can proceed like this:
querySelectorAll()
by the assigned classkeyup
[0-9]
true
orfalse
, as the case may be, validate with aif else
Example