serialize doesn't include hidden fields

JquerySerialization

Jquery 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongruszczyView Question on Stackoverflow
Solution 1 - JqueryJosh StodolaView Answer on Stackoverflow
Solution 2 - JqueryJim SchubertView Answer on Stackoverflow
Solution 3 - JquerySZLView Answer on Stackoverflow
Solution 4 - JqueryKilleRView Answer on Stackoverflow
Solution 5 - JqueryCengiz ÖnkalView Answer on Stackoverflow
Solution 6 - JqueryMark TebaultView Answer on Stackoverflow