2

I have an issue with my code which might be quite obvious but I can't seem to find out the answer.

I have a drop down menu with pre-filled option values in it. Whenever a user clicks on any of the values, they get displayed on a text area using JavaScript. Here's my problem:-

If the user selects 'Hello World' from the drop down, it gets displayed in the text area. if the user types a string or number or anything after that in the text area, then selects the option 'How's your day going', it doesn't get concatenated to the text area, since the user made a change to the text area. How can I get it to concatenate the option values every time a different option is selected. Here's my code:-

HTML

<select name = 'type_of_call' id = 'type_of_call' onchange = 'run()'>
<textarea name = "comments" value = "comments" id = "comments" Required /></textarea>

JavaScript

function run(){
document.getElementById("comments").innerHTML += document.getElementById("type_of_call").value + ', ';
}
abc
  • 45
  • 1
  • 6

1 Answers1

0

You want to set the textarea's value property, not the innerHTML property:

function run(){
  document.getElementById("comments").value += ...;
}
PeterMader
  • 6,987
  • 1
  • 21
  • 31