Focus on a field with maskedinput

Asked

Viewed 24 times

0

Good morning, you guys...

I have in my form a text field with recursive entries. How do I p/after sending a typed value, clear it and get ready for the next entry ? As soon as I type the first character of the next entry it presents the value already typed previously...my code is 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("");
}

1 answer

1

To clear the value of the field, you just need to undo its value before you focus. For the browser autocomplete you can try the 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>

  • Thank you, colleague.... It worked...

  • @Ninja2112, if the solution presented solved your problem you must accept it as an answer. And it is important to ask a question always worry about presenting a [MCVE]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.