serialize doesn't include hidden fields
JquerySerializationJquery Problem Overview
I run serialize on a form, where on of the fields is hidden - and it's a very important field, which should be posted. Is there any way to easily serialize it through jQuery or should I write my own function?
Jquery Solutions
Solution 1 - Jquery
Serialize does include all enabled input
elements with a name
attribute.
Solution 2 - Jquery
Maybe combining the two in a single selector would work?
$(":input,:hidden").serialize();
edit: I just tried the above and it worked. but, $("form").serialize(); should automatically take all inputs as others have mentioned.
Solution 3 - Jquery
You need set the name attribute and check the disabled attribute! The disabled field also not serialized.
Solution 4 - Jquery
Just ran into this problem myself, and hacked out a solution.
The problem has to do with the way JQuery picks up hidden html information. It will not pick up the TEXT of a hidden field as its value, you must use the value= property.
To set it in JQUERY use $(field).val(yourvalue);
Solution 5 - Jquery
you should add name to all elements for serialize function to work properly
Solution 6 - Jquery
I had this problem as well. Out of habit I close my input fields with />. I found that hidden input does not work when closed this way.
<input type="hidden" name="someName" value="someValue" />
does not work.
<input type="hidden" name="someName" value="someValue" >
does work.