tags:

views:

73

answers:

5

How to get Textarea value in jquery, if I am using

<form name="myform"> 
<textarea name="msg" id="msg"></textarea>
</form>

This syntax is not working properly

 var text = $('textarea#message').val();

can anybody tell me about the things ?

+4  A: 

Your idea is right, but your selector is a bit off:

$('textarea#msg').val(); //not "message"

The ID of the ID-selector needs to match exactly :)

Nick Craver
I thought we were using the Semantic Web? ;)
GalacticCowboy
A: 

If your textarea's Id is "msg" then your selector needs to use that.

var text = $('textarea#msg').val();
GalacticCowboy
Would the anonymous downvoter care to comment? (Pretty sure this was a retribution downvote for a negative comment I made on someone else's answer, even though I did *not* downvote them...)
GalacticCowboy
+2  A: 

Have you tried:

$("textarea#msg").val(result.message);

or

$("textarea#msg").val()
VoodooChild
+1  A: 

You appear to be targeting the text area incorrectly. Try var text = $('textarea#msg').val().

g.d.d.c
+3  A: 

$("#msg").val();

Babiker
actually this is the best answer!
adardesign
@adardesign: and why is that?
VoodooChild
Because the selector is a id, So it maps to the native `getElementById()`, in other words, the selector is the fastest. see http://tinyurl.com/2ctdw8c out of many jQuery's best performance articles
adardesign