How to get the value of a text area in javascript
I have a form with a text area input. I am using JQuery to submit a form via an AJAX request to update the database. My problem is that I am having a hard time getting data from the text area input. If there is an id "txtBody" in the input, I 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 any other way to access the data. Any ideas?
a source to share
You add to the database. Have you debugged the actual code to make sure you're not just sending 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>
Execution $('#txtBody').val();
will return the value "test". There are no ifs or buts.
Maybe you should post some more of your codes so that we can determine what is wrong, as I am guessing not the problem you are facing.
a source to share
jQuery documentation suggests val () is not available, these are older versions of jQuery. Is your version up to date?
a source to share