Reputation: 933
I want to create two textboxes and a textarea that concatenates the texts from both input fields. My html code is as follows:
<input class= 'inpo' type='text'/>
<input class= 'inpo' type='text'/>
<textarea id='res' readonly></textarea>
My jquery code is as follows:
$(".inpo").keyup(function(){
var str = "";
$(".inpo").each(function() {
str += $(this).text() + " ";
})
$("#res").val(str);
});
However, it does not work. I do not get anything on my console either.
Upvotes: 0
Views: 20
Reputation: 687
You should use val() not text():
$(".inpo").keyup(function(){
var str = "";
$(".inpo").each(function() {
str += $(this).val() + " ";
})
$("#res").val(str);
});
Upvotes: 1