Reputation: 7
Im trying to pass the textbox value to textarea but I cant come up with the idea how to add new value to the existing in the textarea.
$('#firstnametxt').change(function () {
$('#rev').val($('#firstnametxt').val());
});
$('#lastnametxt').change(function () {
$('#rev').val($('#lastnametxt').val());
});
rev is textarea id.
I would like to seperate entries into new row as well. Thanks.
Upvotes: 0
Views: 638
Reputation: 321
If i understand well you looking for
function setValues(){
$('#rev').val(
$('#firstnametxt').val() + "\n" + $('#lastnametxt').val()
);
}
$('#firstnametxt').change(setValues);
$('#lastnametxt').change(setValues);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="firstnametxt" name="firstnametxt" type="text"><br>
<input id="lastnametxt" name="lastnametxt" type="text"><br>
<textarea id="rev" name="rev"></textarea>
Upvotes: 0
Reputation: 23738
The onchange
is only triggered when focus out of the input. Try onkeypress
instead.
$('#firstnametxt').on('keypress',function() {
$('#rev').val($(this).val());
});
$('#lastnametxt').on('keypress',function() {
$('#rev').val($(this).val());
});
Upvotes: 1