0

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!

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

1 Comment

This way, what happens if I write some text inside input.response-input#1, then write something else in input.response-input#2, then go back to input.response-input#1 to correct something (maybe a typo or completely change it)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.