I want to place the elements of a select to a textarea, the code I have works well to add the text, but the problem arises when I delete the text from the textarea, if I delete something from it, it does not let me put more text back from the select, then I put the code I have.
function agregar(texto){
console.log(texto);
$("#test1").append(texto+"\n");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<title>Problema</title>
</head>
<body>
<select name="" id="test" onchange="agregar($('#test option:selected').text())">
<option value="1">Uno</option>
<option value="2">Dos</option>
<option value="3">Tres</option>
<option value="4">Cuatro</option>
</select>
<br/>
<textarea name="" id="test1" cols="30" rows="10"></textarea>
</body>
</html>
How could I solve this problem, or why is this?
Well, I would solve it in the following way:
textarea
it is a text input element for which it would not capture its value with ,.html()
but with.val()
and likewise it would be assigned since it is really the function that corresponds to it, here is an example: