Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery serialize() leaves out textarea

When I submit a form using jQuery's serialize() method, everything gets submitted except the textarea in the form. Is this a common issue? I can't figure it out. The form works except for just the textarea which stays undefined???

<textarea form="new_note_form" id="note_text" name="note_text" required="required"></textarea>     
like image 239
Amoeba Avatar asked Jul 17 '13 19:07

Amoeba


4 Answers

It does not work until you add name attribute to the textarea.

<textarea id="sLifeStyle3Content" name="sLifeStyle3Content" placeholder="HTML is allowed">   <apex:outputText value="{!sLifeStyle3Content}" /> </textarea> 
like image 90
Daniel Sokolowski Avatar answered Sep 16 '22 11:09

Daniel Sokolowski


No it doesn't.

It works fine. http://jsfiddle.net/nuBkM/

<form>     <input name="foo" value="bar"/><br>     <textarea name="something">lorem ipsum</textarea> </form> 

The JavaScript

console.log($("form").serialize()); // => foo=bar&something=lorem+ipsum  

.serializeArray works too

console.log($("form").serializeArray()); // => [{name: "foo", value: "bar"}, {name: "something", value: "lorem ipsum"}]  
like image 39
Mulan Avatar answered Sep 18 '22 11:09

Mulan


Another work around for this is to turn the textarea value into a variable and pass that with the ajax call...

var comment = $('.note_comment').val();

           $.ajax({
               type: "POST",
               url: '/approot/rewrite.cfm/app.people/insertNote?format=json&Comment=' + comment,
               data: $("form[name='add_note_form']").serializeArray(),
               success: function(data)
               {
              alert('success');         
               }
             });
like image 25
dtharpe Avatar answered Sep 18 '22 11:09

dtharpe


If the textarea is controlled by an editor like tinyMCE, you may need to call tinyMCE.triggerSave(), as described in this answer.

like image 37
grvsmth Avatar answered Sep 20 '22 11:09

grvsmth