Copy data from one field to another [closed]

2

My client requested that I create 2 fields in the system, one as "Cellular" another as "WhatsApp" and next to the WhatsApp field would have a button to copy the value, if the number is the same, someone has an idea how can I do it?

    
asked by anonymous 11.11.2016 / 19:43

2 answers

6

Without much detail it is difficult to help you, but using jQuery, the basis is this

$('#bt-copiar').on('click', function(){
  $('#txt-wpp').val($('#txt-tel').val());    
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><label>Telefone:</label><inputtype="text" id="txt-tel" />
<button id="bt-copiar">Copiar</button>

<br>

<label>Whatsapp</label>
<input type="text" id="txt-wpp" />
    
11.11.2016 / 19:54
5

Only with JavaScript you can do something like this:

function copiaValor() {
  var celular = document.getElementById("campo1").value;
  document.getElementById("campo2").value = celular;
}
<label>Telefone:</label>
<input type="text" id="campo1" />

<br>

<label>Whatsapp</label>
<input type="text" id="campo2" />

<button id="copiar" onclick="copiaValor()">Copiar</button>
    
11.11.2016 / 19:57