Getting Textarea Value with jQuery

Jquery

Jquery Problem Overview


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/

Jquery Solutions


Solution 1 - Jquery

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

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

Solution 2 - Jquery

By using new version of jquery (1.8.2), I amend the current code like in this links http://jsfiddle.net/q5EXG/97/

By using the same code, I just change from jQuery to '$'

<a id="send-thoughts" href="">Click</a>
<textarea id="message"></textarea>

$('#send-thoughts').click(function()
{ var thought = $('#message').val();
  alert(thought);
});

Solution 3 - Jquery

It can be done at easily like as:

     <a id="send-thoughts" href="">Click</a>
     <textarea id="message"></textarea>

        $("a#send-thoughts").click(function() {
            var thought = $("#message").val();
            alert(thought);
        });

Solution 4 - Jquery

change id="#message" to id="message" on your textarea element.

and by the way, just use this:

$('#send-thoughts')

> remember that you should only use ID's once and you can use classes over and over.

https://css-tricks.com/the-difference-between-id-and-class/

Solution 5 - Jquery

try this:

<a id="send-thoughts" href="">Click</a>
<textarea id="message"></textarea>
<!--<textarea id="#message"></textarea>-->

            jQuery("a#send-thoughts").click(function() {
                //var thought = jQuery("textarea#message").val();
                var thought = $("#message").val();
                alert(thought);
            });

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDave KissView Question on Stackoverflow
Solution 1 - JquerybradView Answer on Stackoverflow
Solution 2 - JquerynunjimmimyaView Answer on Stackoverflow
Solution 3 - Jqueryuser1133648View Answer on Stackoverflow
Solution 4 - JquerychitcharonkoView Answer on Stackoverflow
Solution 5 - JqueryVismariView Answer on Stackoverflow