dlofrodloh
dlofrodloh

Reputation: 1744

How to get text area value from a javascript element

If I have a div element and I add a textarea to the innerHTML like the following:

tMessageWindow.innerHTML="<textarea rows = '22' cols='67'> Test text </textarea>"

How can I then retrieve the value of the text area?

I've tried tvalue=tMessageWindow.value and that doesn't work of course.

Upvotes: 0

Views: 59

Answers (3)

Alfonso Jim&#233;nez
Alfonso Jim&#233;nez

Reputation: 1245

Add an id to the textarea (for example id="foobar") so you can then get the value by using

document.getElementById("foobar").value;

Upvotes: 1

sp00m
sp00m

Reputation: 48817

tMessageWindow.childNodes[0].value should suit your needs.

Upvotes: 1

JLRishe
JLRishe

Reputation: 101680

How about:

var tvalue = tMessageWindow.getElementsByTagName("textarea")[0].value;

Upvotes: 2

Related Questions