This occurs because that id
is a unique reference to an element, so it only considers the first element created, but you can use class
which can be used for several elements.
<input class="textInput" type="text" value="teste">
<input class="textInput" type="text" value="teste">
$('.textInput').on('keyup', function(){
console.log($(this).val());
});
To better understand the attribute id
read the MDN documentation and class
MDN documentation
To set the value on your property date
would be as follows
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<script
src="https://code.jquery.com/jquery-3.4.0.js"
integrity="sha256-DYZMCC8HTC+QDr5QNaIcfR7VSPtcISykd+6eSmBW5qo="
crossorigin="anonymous"></script>
</head>
<body>
<div class="col-xs-4 offset-xs-4">
<input id="textInput1" class="textInput" type="text" value="teste">
<span date="" id="date1"></span>
<input id="textInput2" class="textInput" type="text" value="teste">
<span date="" id="date2"></span>
</div>
</body>
</html>
<script type="text/javascript">
$('#textInput1').on('keyup', function () {
console.log('input1 valor: ' + $(this).val());
$("#date1").attr("date", $('#textInput1').val());
});
$('#textInput2').on('keyup', function () {
console.log('input2 valor: ' + $(this).val());
$("#date2").attr("date", $('#textInput2').val());
});
</script>
Obs:
I started using the identifier id
in the elements since you want the
values of the specific element.
Because the id is unique, it can only be referenced to an element, use class, exchange id="textInput" to class="textInput" => $('. textInput').
– Joan Marcos
It is to appear the value of the first input in a span and the other input in the other span ?? I did not understand very much not
– Joan Marcos
if I type in input 2 he writes in span 2 if I write in input 1 he writes in span 1 the way that if I write in input he writes in both span
– diogo Dsa