Takes an input value executes function and returns in another input

Asked

Viewed 18 times

-1

Hello!

I want to perform a very simple function, which is to take the CPF of an input, remove the points and strokes and return the value in another input without the points and strokes.

The first part I managed to do, but I do not know how to return the function in the other input.

let botao = document.querySelector("#botao");
let retornaCpf = document.querySelector("#retornaCpf")

botao.onclick = function() {
  let cpf_com_ponto_e_traco = document.querySelector("#cpf-com-ponto-e-traco").value;
  let cpf_sem_ponto_e_traco = cpf_com_ponto_e_traco.replace(".", "").replace(".", "").replace("-", "");
  
  alert(cpf_sem_ponto_e_traco);
}
<input type="text" id="cpf-com-ponto-e-traco">
<input type="text" id="retornaCpf">
<button id="botao">Pegar CPF</button>

1 answer

0

Simple:

retornaCpf.value = cpf_sem_ponto_e_traco;

That is, to get the value you read the value of the first input, and to fill in the other you define your value.

Browser other questions tagged

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