开发者

How do I get the value of a textarea in jquery?

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 ?


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 :)


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


Have you tried:

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

or

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


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


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

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


your code :

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

Your id name is : msg, not message so your code should be like this :

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜