Good Evening and thanks all in advance!
i have this input:
<div class="ref-control">
<h3>Por Favor passe o passe o cartão pelo leitor</h3>
<form>
<label for="leitura-nim"> Leitura de Nim
<input tabindex="99" autofocus type="text" name="leitura-nim" id="leitura_nim" />
</label>
</form>
</div>
and this input get's autofocus when the page is loaded, so far so good, my problem is, when the user click outside the input, i need it to become autofocus again when the user press a key on keyboard or when the input is recived from some device(it is the same as typing it is tested), so far i got this js, but it does not enable the focus on keypress.
var leituraNim = $('#leitura_nim');
leituraNim.on('keypress', function() {
document.getElementById('leitura_nim').contentEditable = true;
document.getElementById('leitura_nim').focus();
});
leituraNim.on('keyup', function() {
if (leituraNim.value.length == 8) {
leituraNim.submit();
}
});
can you guys help me out?
thanks Rob
Try something like I have below. Note the extra
#form
ID tag for<form id="form">
. I think what you're trying to achieve is focus on any keypress when the input is not already focused, if so,$(document).on("keypress")
should do the trick.