Echchama Nayak
Echchama Nayak

Reputation: 933

jquery keyup not working while extracting text from input fields

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

Answers (1)

Caedmon
Caedmon

Reputation: 687

You should use val() not text():

$(".inpo").keyup(function(){
        var str = "";
    $(".inpo").each(function() {
        str += $(this).val() + " ";
    })
    $("#res").val(str);
});

Upvotes: 1

Related Questions