JQuery: .val () not working for textarea

I am trying to read the contents of a text field but it .val()does not work for my text field. I would be happy if someone has a solution for me. Here is my code:

HTML:

<textarea id="details" class="required" rows="5"></textarea>

JS:

$.ajax({
      type: "GET",
      url: "reserve.php",
      data: {
            details : $('#details').val(),
            ...
      },
      ...
});

Thank!

+5
source share
7 answers

val() works just fine ... You should have your error elsewhere.

Example

Your selector probably doesn't match. Check for typos, and if you applied the correct prefix ( #for identifier or .for class)

+6
source

This is a valid request since I ran into exactly the same problem and can report the following:

  • No - this is not a selector, one valid object is returned
  • -
  • , , HTML .

, , :

$('#myTextArea')[0].value 
+4

. , id "comment". JQuery , . , , AJAX. "" ( ), . , .

+2

, , . , $('textarea'). , :   $ ( ' ') ( '');.

, :   $ ('textarea'). text ('my new value');

+2

, .

:.

:

'content': $(this).find('#text_content').val(),

:

'content' : $(this).find('input[name=text_content]').val(),

, ( ), .

+1

details: encodeURIComponent ($ ('# details'). val())

0

right-click TextAreaFor and select Inspect. Use the identifier generated by your browser, for some reason it generates its own identifier for TextArea, even if you specify it in htmlAttributes. in code: @ Html.TextAreaFor (model => model.PendingUserDto.PendingUserNotes, new {htmlAttributes = new {@ class = "form-control", id = "pendingUserNotes"}}) in the verification window: test notes

0
source

All Articles