Filling of two equal inputs

Asked

Viewed 69 times

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 write something in the first input(discount) automatically the same thing is filled in the second input

  • 1

    Have you tried some code?

2 answers

6


You can do it like this, with native Javascript:

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

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

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

example: https://jsfiddle.net/w0gvo7yv/

4

You should assign an event to txt that will be used to type. See the example I did 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>
<input type="text" id="txtUm" />
<input type="text" id="txtDois" />

Browser other questions tagged

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