Focus on a field with maskedinput

0

Good morning, guys ...

I have a text field with recursive entries in my form. How do I after posting a typed value, clean it and leave it ready for the next entry? As soon as I type the first character of the next entry it displays the previously entered value ... my code looks like this:

if(valor == 0){
  alert("Digitou zero.");
  document.frmsaidadoscor.txtnumdo.focus();
}else{
  dos.push(valor);
  txtnumdo.value='';
  cont = cont + 1;
  document.frmsaidadoscor.txtnumdo.focus("");
}
    
asked by anonymous 27.11.2018 / 13:57

1 answer

1

To clear the value of the field, you simply undo its value before you focus. For autocomplete of the browser you can try autocomplete="off" , but some ignore this instruction.

let cont = 0;
let dos = [];
let input = document.getElementById('txtnumdo');

let salvar = function() {

  let valor = input.value;
  if (valor == 0) {
    alert("Digitou zero.");

  } else {
    dos.push(valor);
    txtnumdo.value = '';
    cont = cont + 1;

  }

  input.value = null;
  input.focus();

  console.clear();
  console.log(dos);
}
<form autocomplete="off">
<input id="txtnumdo" type="text" autocomplete="false" />
<input type="button" onclick="salvar()" value="Salvar" />
</form>
    
27.11.2018 / 18:13