1

I have a form with checked checkboxes. Its serialization is not returning those checked checkboxes. This is the jQuery code I am using to perform the serialization.

$('form.subscribe').serialize()

The above serialization returns

email= 

This is the markup:

<form class="subscribe">
<div class="body">
    <div class="email input">
        <input name="email" placeholder="your email address" />
    </div>
    <div class="expandable">
        <div class="fieldLabel emphasis">I am a:</div>
        <div class="checkbox">
            <input id="isDeveloper" type="checkbox" />
            <label for="isDeveloper">Developler<label> 
        </div>
        <div class="checkbox">
            <input id="isDesigner" type="checkbox" />
            <label for="isDesigner">Designer</label>
        </div>
        <div class="checkbox">
            <input id="isHR" type="checkbox" />
            <label for="isHR">Talent Coordinator</label>
        </div>
        <div class="checkbox">
            <input id="isPM" type="checkbox" />
            <label for="isPM">Project Manager</label>
        </div>
        <div class="fieldLabel emphasis">Email me about:</div>
        <div class="checkbox">
            <input id="wantsCollab" type="checkbox" checked="checked"/>
            <label for="wantsCollab">Collaboration</label>
        </div>
        <div class="checkbox">
            <input id="wantsBlog" type="checkbox" checked="checked" />
            <label for "wantsBlog">Blog Posts</label>
        </div>
    </div>
    <div class="button">
        <input class="emphasis" type="submit" value="subscribe">
    </div>
</div>
</form>

As you can see, there is 1 text input and 6 checkboxes. 2 of those checkboxes are checked, yet only the text input is being returned in the serialization.

2
  • 2
    none of your checkboxes have a name attribute
    – wirey00
    Commented Sep 27, 2012 at 18:35
  • 3
    For a form element's value to be included in the serialized string, the element must have a name attribute. -- jquery.com --
    – HansElsen
    Commented Sep 27, 2012 at 18:37

2 Answers 2

4

Your checkboxes do not have name attributes, and your email input has no type specified. Also your form has no action or encoding specified, which you might want for purposes of graceful degradation.

0
1

From the jQuery docs

Note: Only "successful controls" are serialized to the string. No submit button value is serialized since the form was not submitted using a button. For a form element's value to be included in the serialized string, the element must have a name attribute. Values from checkboxes and radio buttons (inputs of type "radio" or "checkbox") are included only if they are checked. Data from file select elements is not serialized.

Not the answer you're looking for? Browse other questions tagged or ask your own question.