I have a problem using onkeyup
in a date mask that is as follows: when I try to use backspace to modify the date, I can not get past the bar (just hold the button pressed). The bar disappears and pops up (test here in fiddle , or below under "Run snippet", type a date any and then try to delete).
This only happens if I am using onkeyup
, with onkeypress
is normal (but I have to use onkeyup
, because it also serves to enable a button if the date validates, and it has to be when typing, and not by losing focus ...).
function formatar(mascara, documento) {
var i = documento.value.length;
var saida = mascara.substring(0, 1);
var texto = mascara.substring(i);
if (texto.substring(0, 1) != saida) {
documento.value += texto.substring(0, 1);
}
}
<input class="form-control" type="text" maxlength="10" placeholder="dd/mm/aaaa" onkeyup="formatar('##/##/####', this)" name="Tinsem3" id="Cinsem">
Is there a way?