views:

87

answers:

3

Hi there, I'm have a very annoying issue with a textarea when trying to retrieve its content.

When I call $('#formMessage').text() I always get the textarea's original value, doesn't matter how much I write or delete of it, it keeps returning me the original content.

I'm not posting the code because it's really simple. A textarea within a form and let's say an alert() to check the textarea's content.

Any idea why this might be happening??

PS: if I try to modify the content by doing .text('modified content') it does get modified, and when I ask for the .text() it now returns the modified value. What's going on here?

PS: let me know if this isn't clear enough. Thanks in advance.

+3  A: 

You can use the jQuery .val() function instead of .text() to get the content of a textarea.

<textarea id="formMessage">blah blah</textarea>

$("#formMessage").val(); // returns "blah blah"
jake33
awesome man (y)
sanchy
+9  A: 

Try this:

$("#formMessage").val()
Topera
awesome man (y)
sanchy
+1  A: 

"The .text() method cannot be used on input elements. For input field text, use the .val() method."

straight from the documentation

Scott M.