jquery - val(); returning nothing -


Using jQuery ... I have a textarea of ​​ val (); trying to get ... and it is not working you said:

What am I doing?

  & lt; Script type = "text / javascript" src = "jquery-1.5.1.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Function () {$ (".comment_button"). (Function () {var test = $ ("# content"). Val (); var data string = 'content =' + test; warnings ('you Said: '+ test);});}); & Lt; / Script & gt; & Lt; Style & gt; #error, #success {display: none;} & lt; / Style & gt; & Lt; Php included 'inc / main.php' ;? & Gt; & Lt; H1 & gt; Trial & lt; / H1> & Lt; Div id = "error" & gt; Error ... & lt; / Div & gt; & Lt; Div id = "success" & gt; Success ... & lt; / Div & gt; & Lt; Form name = "form" = "ask.php" method = "post" & gt; & Lt; Textarea rows = "5" cols = "50" name = "content" id = "content" name = "thequestion" & gt; & Lt; / Textarea & gt; & Lt; Br / & gt; Input name = "submit" value = "submit!" Type = "submit" category = "comment_button" /> & Lt; / Form & gt; & Lt; Div id = "flash" & gt; & Lt; / Div & gt; & Lt; Div id = "display" & gt; & Lt; / Div & gt;  

I modified your code in a bit and it worked for me. .

The biggest change I make was using .submit () trigger, not .click () , .click () Do not allow you (preventively, if there is anything) to stop the form.

The revised sections are:

  $ ("# comment_form"). Submit (function () {Var test = $ ("# content") .val (); var datastring = 'content =' + test; warning ('you said:' + test); the statement is false; // submit in order to stop });   

And this:

  & lt; Form name = "form" id = "comment_form" action = "ask.php" method = "post" & gt;    

Comments