简体   繁体   中英

Concatenate values from drop down along with user input

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 + ', ';
}

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

function run(){
  document.getElementById("comments").value += ...;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM