Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Textarea Value with jQuery

Tags:

jquery

This is driving me crazy - why doesn't my code work?

<a id="send-thoughts" href="">Click</a> <textarea id="#message"></textarea>              jQuery("a#send-thoughts").click(function() {                 var thought = jQuery("textarea#message").val();                 alert(thought);             }); 

alerts undefined.

http://jsfiddle.net/q5EXG/

like image 562
Dave Kiss Avatar asked Apr 18 '11 20:04

Dave Kiss


People also ask

How can get value entered textbox using jQuery?

To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.

How do you value a text area?

Use the value property to get the value of a textarea, e.g. const value = textarea. value . The value property can be used to read and set the value of a textarea element. If the textarea is empty, an empty string is returned.

Can textarea have value?

From the MDN documentation: " <textarea> does not support the value attribute".

How do I display textarea content in HTML?

Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.


1 Answers

you have id="#message"... should be id="message"

http://jsfiddle.net/q5EXG/1/

like image 121
brad Avatar answered Sep 23 '22 19:09

brad