0

Update: Ok, I need to be shot. I left out a little bit of form code to cut down on the length of the post. Here's the full code:

<form name="userupdate" id="userupdate" method="post">
<input type='hidden' name='username' id='username' value='andyd273' />
<input type='hidden' name='setusertype' id='setusertype' value='1' />
<table align="left" border="1" cellspacing="0" cellpadding="3" class="bodytext">
<tr><td>andyd273</td></tr>
<tr><td>
<input type='checkbox' name='DealerType[]' id='GM' value='1' /> GM<br>
<input type='checkbox' name='DealerType[]' id='Chrysler' value='2' /> Chrysler<br>
<input type='checkbox' name='DealerType[]' id='Ford' value='3' /> Ford<br>
</td></tr>
</table><br>
<input type='button' value='Save' onclick='javascript: formSubmit();' />
</form>

I figured I'd try something out, and removed the table stuff, just leaving the plain form inputs, and the checkboxes started working just like they do in Chrome.

So, new question: Why won't serialize work in IE when the inputs are inside of a table? Thanks to everyone that tried to help solve the first incomplete question!

Old question left for completeness:

I am trying to get a form to serialize. It works in Chrome and Firefox, but not in Internet explorer.
Example:

<input type='hidden' name='username' id='username' value='andyd273'>
<input type='hidden' name='setusertype' id='setusertype' value='1'>
<input type='checkbox' name='DealerType[]' id='GM' value='1' /> GM<br>
<input type='checkbox' name='DealerType[]' id='Chrysler' value='2' /> Chrysler<br>
<input type='checkbox' name='DealerType[]' id='Ford' value='3' /> Ford<br>

In Chrome I get:

Array
(
    [username] => andyd273
    [setusertype] => 1
    [DealerType] => Array
        (
            [0] => 1
            [1] => 3
        )

)

But in IE I only get:

Array
(
    [username] => andyd273
    [setusertype] => 1
)

So I'm not sure what needs to be done with it to make it work in IE.

/Old question

3
  • Have you tried it with a different name attribute for the checkboxes? Specifically, one without the braces? I'd poke at it myself, but I don't have my IE VM handy at the moment.
    – Carl
    Commented Dec 11, 2012 at 15:30
  • I changed it, just for a test, to be DealerType1, DealerType2, DealerType3 instead of the braces, and it still is only sending the two hidden inputs. Very weird.
    – AndyD273
    Commented Dec 11, 2012 at 15:50
  • ah, with the update, the answer is easy (if sad). Nesting input elements in table is not legal HTML.
    – Carl
    Commented Dec 11, 2012 at 16:32

2 Answers 2

1

jQuery's serialize does not include unchecked checkboxes.

Check out this fiddle:

http://jsfiddle.net/UGaEp/3/

You can find more from the following question:

jQuery serialize does not register checkboxes

Ignore the code, wouldn't let me post an answer.

$('#test').on('click', '#submit', validate);

function validate() {
    var data = $('#test').serialize();
    console.log(data);
}​
9
  • I'm actually Ok with not including unchecked check boxes. I actually only care about the checked ones. And it's working in non IE as is.
    – AndyD273
    Commented Dec 11, 2012 at 16:06
  • I'm not understanding what you mean by "working in non IE" the example above should work in ie. I've updated the fiddle to work with alerts rather than console.logs. Commented Dec 11, 2012 at 16:09
  • You are correct, it should have worked as entered. Unfortunately I had left a little out. My apologies. See updated question for better explanation.
    – AndyD273
    Commented Dec 11, 2012 at 16:26
  • I really think I'm missing something here lol. I checked the following fiddle in ie7-ie9 and it seems to be serializing. jsfiddle.net/UGaEp/3 Commented Dec 11, 2012 at 16:32
  • I'm seeing the following text when checkboxes are checked: username=andyd273&setusertype=1&DealerType%5B%5D=1&DealerType%5B%5D=2&DealerType%5B%5D=3 Commented Dec 11, 2012 at 16:42
1

Update:

Because nesting input elements in table elements is not legal HTML syntax. Chrome and Firefox smooth over this "problem", though, notably: Safari doesn't always.

To answer the comments - if the order is form > table > etc > input that's incorrect, table > table stuff > form > input is fine.

The "right" way to do formatting is basically divs or fieldsets and then style attributes. The various display options will probably be what you want (inline and inline-block probably being most useful, though table and assorted derivatives depending on which versions of IE you have to support) -- read here to figure out what's at your disposal, though possibly some chicanery with setting heights and widths.

Old:

Can you replace the checkbox interface with a multi-select interface? That may be one way to work around the...fussy...IE implementation. That is:

<select multiple name="DealerType">
<option value="1">GM</option>
//...etc
</select>

Also, from your sample, your hidden elements aren't closed (terminated with /> instead of >). Depending on which IE you're dealing with, that could be part of the problem.

Another clarifying comment: what version of jQ are you using?

7
  • you were right about the non closed inputs, and the fact that the multi select helped me figure out that the problem is not with the form inputs. I updated the question to better reflect the problem.
    – AndyD273
    Commented Dec 11, 2012 at 16:30
  • If you run inputs inside a table though the w3 html validation service it comes out valid. For granted that is assuming they are in the proper order table > tr > td > input. Commented Dec 11, 2012 at 16:36
  • I've used tables for formatting forms forever. It's an easy way to make text boxes line up for instance, and at least for non jquery stuff (traditional form submit) it's always worked fine. If it's not legal HTML that's fine, I can learn new things, but what is the correct way to format a form and make things line up?
    – AndyD273
    Commented Dec 11, 2012 at 16:36
  • A table is completely fine. Commented Dec 11, 2012 at 16:40
  • @DennisMartinez I disagree, see for example: stackoverflow.com/questions/5967564/form-inside-a-table
    – Carl
    Commented Dec 11, 2012 at 17:00

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