I'm going off this existing example on StackOverflow, which simply adds a textbox value to a textarea as a new line with some accompanying text.
I modified it to work via onChange however, and am adding multiple textboxes that will each add new lines if there is a value present; all works fine:
$(document).on('change', '#dlnum input', function (e){
var inputEl = $(this);
var textareaEl = $('#BoloDesc');
//If input has any text
if($(inputEl).val().length){
//Appending line to textarea
$(textareaEl).val($(textareaEl).val()+'DL NUMBER'+' '+$(inputEl).val()+"\r\n");
return false;
}
});
All this works fine; my question is, just as the textbox value is added or appended to the textarea when a value exists in that textbox, I'd like for the textarea to remove that particular textbox value from the textarea when it's empty.
I know Googling this brings up setting .val='', but of course this will clear out the entire textarea, which isn't what I want to do. I simply want to remove that particular textbox value while keeping all of the others in there.
How can I do this?
Original StackOverflow post is here: append textbox value to textarea on enter