Dave Kiss
Dave Kiss

Reputation: 10485

Error getting textarea value with jQuery

Ok, my last post was a failure, so let's try this again.

If you visit www.davekiss.com and click on the icon in the top right corner, you'll see a customized implementation of a jQuery slider. Click on the "Contact" button and fill out the textarea.

Basically, what I am trying to is save the value in that textarea to a javascript variable, but for some reason, that 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?

Upvotes: 0

Views: 2526

Answers (4)

brad
brad

Reputation: 32345

You also have a syntax parse error on line 232. You're missing a ) to your append function.

Upvotes: 0

Christopher Armstrong
Christopher Armstrong

Reputation: 7953

Your textarea has a name of 'message', but not an id. Your selector is selecting based on an ID, but no such element exists. Either give the textarea the id of "message", or change your selector to find by name (former is probably preferred).

Upvotes: 4

Blender
Blender

Reputation: 298176

Try getting it's .text():

var thought = jQuery("textarea#message").text();

Upvotes: 0

pmaruszczyk
pmaruszczyk

Reputation: 2155

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

Upvotes: 0

Related Questions