Satch3000
Satch3000

Reputation: 49384

JQuery Passing Json value to textarea issue

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

Answers (1)

1252748
1252748

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

Related Questions