RogueWolf
RogueWolf

Reputation: 135

Add multiple input values to textarea on keyup

I wonder if someone could please help me. I have multiple inputs that need to insert into a textarea as you type. I've gotten that to work but when I start typing in a new input it resets the textarea with only that text from the input. I need it to continuously add from each input.

$(responseList).on("keyup", ".response-input", function(e) {
    $("textarea").text(e.target.value);
});

Any assistance would be greatly appreciated!

Upvotes: 0

Views: 466

Answers (2)

Not sure 100% about your setup and what you want to achivement in way of function but you could try something like this.

var t = $(".response-input").map(function() {
  return $(this).val();
}).get().join(" ")
$("textarea").text(t);

Demo

$(document).on("keyup", ".response-input", function(e) {
  var t = $(".response-input").map(function() {
    return $(this).val();
  }).get().join(" ")
  
  $("textarea").text(t);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input class="response-input" />
<input class="response-input" />
<input class="response-input" />
<textarea></textarea>

Upvotes: 2

Kip
Kip

Reputation: 513

Use .append() for this. ✌️ https://api.jquery.com/append/

$(responseList).on("keyup", ".response-input", function(e) {
    $("textarea").append(e.target.value);
});

Upvotes: 0

Related Questions