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!
CodePudding user response:
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 />
<input />
<input />
<textarea></textarea>
CodePudding user response:
Use .append() for this. ✌️ https://api.jquery.com/append/
$(responseList).on("keyup", ".response-input", function(e) {
$("textarea").append(e.target.value);
});
CodePudding user response:
$(responseList).on("keyup", ".response-input", function(e) {
$(this).val($(this).val() '' e.target.value);
});