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
It leaves out the textarea , unless you Remove 'form="new_note_form"' from your textarea element.
I know it's against good practices, but, if you want to use jQuery's serialize function, you gotta remove this attribute from textarea element.
I have the same experience. Submitting a form using $("#form_id").serialize() does not include the textarea fields. This behavior is consisent for the past 2 years in the only form that has textarea elements. Every now and then I re-examine form and code to conclude that it should work, but doesn't.
My work-around is, unsurprisingly, to first move the content of the textareas into hidden text boxes and then serialize the form data.
We ran into the same problem with a textarea not being serialized despite having the name attribute set, and noticed it depended on where in the form the textarea was placed. We had the luxury of moving the textarea to another location on the form to resolve the problem.
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"}]
If the textarea is controlled by an editor like tinyMCE, you may need to call tinyMCE.triggerSave()
, as described in this answer.
Works fine in the fiddle. http://jsfiddle.net/Ultimate/2Ey2A/ Testing with
$('button').click(function(){
alert($('form').serialize());
});