Reputation: 2327
I am trying to add text in the the <textarea>
when an on change event occurs.
It works perfectly fine in the first change event. But when I delete the text inside the text area and preform another change event it does not work add the text anymore?
I am really confused on why its not working. Below is a snippet of what I am trying to accomplish.
$("#test").on("change", function() {
$("#textarea_test").text("Hello");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="test" id="test">
<option value="Test1">Test 1</option>
<option value="Test2">Test 2</option>
</select>
<textarea name="textarea_test" id="textarea_test" cols="30" rows="10"></textarea>
Upvotes: 0
Views: 53
Reputation: 817128
.text
changes the inner content of the textarea, which is used as default value. Once the value was changed by the user, changing the default value won't have any effect.
Use .val
to change the value, just like with any other form control element.
Upvotes: 5