i have this form and im trying to get the value from the text area. for some reason it doesn\'t want to.
all Values is always taken with .val()
.
see the code bellow:
var message = $('#message').val();
You should check the textarea is null before you use val() otherwise, you will get undefined error.
if ($('textarea#message') != undefined) {
var message = $('textarea#message').val();
}
Then, you could do whatever with message.
You can also get value by name instead of id like this:
var message = $('textarea:input[name=message]').val();
you should use val()
instead of html()
var message = $('#message').val();
You don't need to use .html()
. You should go with .val()
.
From the doc of .val():
The
.val()
method is primarily used to get the values of form elements such asinput
,select
andtextarea
. When called on an empty collection, it returnsundefined
.
var message = $('#message').val();
in javascript :
document.getElementById("message").value