I am attempting to set a value in a textarea field using jquery with the following code:
$("textarea#ExampleMessage").attr("value", result.exampleMessage);
The issue is, once this code executes, it is not altering the text in the textarea?
However when performing an alert($("textarea#ExampleMessage").attr("value"))
the newly set value is returned?
To set or get the text value of input or textarea elements, use the . val() method. To get the value of a script element, use the . html() method."
From the MDN documentation: " <textarea> does not support the value attribute".
Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.
Have you tried val?
$("textarea#ExampleMessage").val(result.exampleMessage);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With