Reputation: 49384
I am having a problem passing a json value to a textarea.
This works:
alert(results.messages[0].text); //Result is Message 1
$("#myTextarea").val('Some Message'); //Adds Some Messsage to myTextarea
My problem is when I try this:
$("#myTextarea").val(results.messages[0].text);
This above does not add the value to the textarea.
Any ideas why?
Upvotes: 0
Views: 676
Reputation: 15372
Use text
for text area. What you have should work. Don't forget to parse your JSON.
var results = '{"messages":[{"text":"some text from json"}]}'
results = JSON.parse(results);
$("textarea").text(results.messages[0].text);
Upvotes: 2