I want to copy text from input to its own input. Because I have a number of them waiting.
For example : src1 to dest1 ,src2 to dest2 ...src5 to dest5
I don't want to pair them with IDs so I wrote:
$(document).ready(function() {
var $src = $('.src'), //source value
$dst = $src.attr('data-dest'); //destination id from .src data-dest
$src.on('input', function() {
$dst.val($src.val()); //text from .src will be here
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Src 1: <input type='text' class='src' data-dest="dest1"> Dest 1: <input type='text' id='dest1' readonly>
<br /> Src 2: <input type='text' class='src' data-dest="dest2"> Dest 2: <input type='text' id='dest2' readonly>
But it's not working as expect. JS here : http://jsfiddle.net/nobuts/vsz7bt5L/5/