
Gabriel F. answered 10/31/19
Tutor
5.0
(85)
Full stack Javascript Engineer
Hi there. I am not sure I completely understand what you want to do but the code below adds text to a textarea when user types on an input field (seems to me this is what you asked):
<style>
textarea {
min-width: 200px;
min-height: 100px;
}
label{
display: block;
margin-top: 10px;
}
input {
display: block;
width: 200px;
}
</style>
<div id="container">
<textarea>
Some initial text...
</textarea>
<label for="input">Type text to be added to textarea</label>
<input type="text" id="input">
</div>
$('input').on('input', (e) => {
let value = e.target.value;
// append only the last character typed
$('textarea').append(value[value.length-1]);
});
I hope this helps!