Login

A problem with jQuery’s .serialize() and the answer

I was having a problem with the jQuery .serialize() function and the good news is that I found the answer to this problem.

The Problem
The jQuery .serialize() function was returning “” or nothing. Not what I wanted to say the least. Here was the setup. I was using .serialize() like this:

...
$(this).parents('.ARow').serialize()
...

and the xhtml was:

<form class="ARow">
<input class="food_state" size="10" type="text" />
<input id="NewFoodState" type="button" value="Add New Food State" />
</form>

The Answer
The problem was that .serialize() outputted “”. The answer was that if an input does not have a “name” field then .serialize() skips it. Of course that makes sense but sometime simple reasons can be overlooked. Therefore when the xhtml is updated to:

<form class="ARow">
<input class="food_state" name="food_state" size="10" type="text" />
<input id="NewFoodState" type="button" value="Add New Food State" />
</form>

The output of .serialize() becomes, as desired, “food_state: raw”. I hope this helps someone else.

This page is using: [download id="1"]

Related posts:

  1. Grabbing a subsection of input field values
  2. Comparing File Download Managers
This entry was posted in jQuery. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted August 16, 2009 at 10:33 pm | Permalink

    Much appreciated! I’ve been banging my head against this for a while, this post was exactly what I needed. Thanks!

  2. Curtis M. Humphrey
    Posted August 17, 2009 at 10:24 am | Permalink

    I’m glad it helped.

  3. Posted November 8, 2009 at 11:51 am | Permalink

    you gonna face other problems just use:
    .serializeArray() – i used this on http://turizmas.info changing from prototype .serialize to jquery, and it works fine and same as protype serialization.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">