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/
To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.
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.
From the MDN documentation: " <textarea> does not support the value attribute".
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.
you have id="#message"
... should be id="message"
http://jsfiddle.net/q5EXG/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With