Filling two equal inputs

3

Well I have the following problem, I have two inputs:

Desconto<input type="text" name="desconto" id="desconto" style="width: 100px" > 

and

Observação<input readonly="true" type="text" name="obs" id="obs" style="width: 400px; height: 30px" >

I would like as soon as I wrote something on the first input (discount) the same thing would automatically be populated in the second input

    
asked by anonymous 07.01.2016 / 18:05

2 answers

6

You can do this with native JavaScript:

var desconto = document.getElementById('desconto');
var obs = document.getElementById('obs');

desconto.addEventListener('keyup', function() {
    obs.value = this.value;
});

So you use the keyup event to run a function that assigns to #obs the value of the element that triggered the event, ie #desconto

example: link

    
07.01.2016 / 18:11
4

You must assign an event to the txt that will be used to type. See the example I made using keyup .

$('#txtUm').on('keyup', function () {
  $('#txtDois').val($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text" id="txtUm" />
<input type="text" id="txtDois" />
    
07.01.2016 / 18:09