I have two text box values:-
var pickup = $('#txt-pickup');
var destination = $('#txt-destination');
and I want to swap the two values as follows:-
pickup.val(destination.val());
destination.val(pickup.val());
However, the above will always set both values as the same value. (same as the destination value)
Is there a way of changing both of these at the same time?
I made a jsfiddle for you:
<input id="txt-pickup" type="text"/>
<input id="txt-destination" type="text"/>
<input id="change" type="button" value="Swap"/>
$(document).ready(function (){
$("#change").on('click',function(){
var pickup = $('#txt-pickup').val();
$('#txt-pickup').val($('#txt-destination').val());
$('#txt-destination').val(pickup);
});
});
JSFIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With