Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading