admin管理员组文章数量:1400188
I have a form with a text area input. I'm using JQuery to submit the form via an AJAX request in order to update a database. My problem is that I'm having difficulty retrieving the data from the text area input. If the input has an id of "txtBody" I have tried:
var body = $("#txtBody").val(); // This adds 'undefined' to the database
var body = $("#txtBody").text(); // This adds nothing to the database
var body = $("#txtBody").html(); // This adds 'NULL' to the database
I can't think of how else to access the data. Any ideas?
I have a form with a text area input. I'm using JQuery to submit the form via an AJAX request in order to update a database. My problem is that I'm having difficulty retrieving the data from the text area input. If the input has an id of "txtBody" I have tried:
var body = $("#txtBody").val(); // This adds 'undefined' to the database
var body = $("#txtBody").text(); // This adds nothing to the database
var body = $("#txtBody").html(); // This adds 'NULL' to the database
I can't think of how else to access the data. Any ideas?
Share Improve this question edited May 16, 2009 at 23:41 fmsf 37.2k49 gold badges153 silver badges196 bronze badges asked May 16, 2009 at 23:31 musoNic80musoNic80 3,6969 gold badges41 silver badges49 bronze badges2 Answers
Reset to default 5You say adds to the database. Have you debugged the actual code to make sure you're not just sending the data with one variable name and trying to add it with another? Because if you have a field like this:
<input type='text' id='txtBody' value='test'>
Or like this:
<textarea id='txtBody'>test</textarea>
Doing $('#txtBody').val();
will return the value "test". There's no ifs or buts about it.
Maybe you should post some more of your code so we can spot what is wrong, as I am guessing that's not the actual problem you are having.
The jQuery documentation suggests that val() was not available is older versions of jQuery. Is your version up to date?
本文标签: jqueryHow to retrieve the value of a text area in javascriptStack Overflow
版权声明:本文标题:jquery - How to retrieve the value of a text area in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744223065a2595960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论