Error getting textarea value using jQuery

Ok, my last post was unsuccessful, so try again.

If you go to www.davekiss.com and click on the icon in the upper right corner, you will see an individual implementation of the jQuery slider. Click the "Contact Us" button and fill in the text box.

Basically, I am trying to store the value in this textarea of โ€‹โ€‹a javascript variable, but for some reason this variable is undefined.

The code in question:

jQuery("a#send-thoughts").click(function() { var thought = jQuery("textarea#message").val(); alert(thought); /*jQuery.ajax({ type: "POST", url: "process.php", data: "message=" + message, success: function(msg){ alert( "Data Saved: " + msg ); } });*/ }); 

Any ideas?

-one
jquery
Apr 18 2018-11-21T00:
source share
4 answers

Your text box has the name "message", but not an identifier. Your selector selects based on the identifier, but such an element does not exist. Either give textarea the identifier for the โ€œmessage,โ€ or change your selector to search by name (probably the previous option is preferable).

+4
Apr 18 2018-11-21T00:
source share

You should use html() instead of val() .

0
Apr 18 '11 at 9:15 a.m.
source share

Try to get .text() :

 var thought = jQuery("textarea#message").text(); 
0
Apr 18 '11 at 9:15 a.m.
source share

You also have a syntax error on line 232. You are missing ) for your add function.

0
Apr 18 2018-11-21T00:
source share



All Articles