0

I've noticed that if you exclude a Name and ID from a form element serializeArray will not return it's value. Is this correct/by design? Just curious...

<form id="myForm" name="JimTheForm">
  <input type="text" value="serializeArray doesn't see me" />
  <input id="someID" name="someName" type="text" value="serializeArray sees me!" />
</form>

in this example the first text field will not be included in serializeArray() but the second text field will because it has a name and id, i think???

  • Every `input` element must have a name, so your invalid code is being ignored. – Rory McCrossan Oct 21 '13 at 13:27
  • This is good to know. I don't want serializeArray to pickup this information. Thanks for the info! – Nick Stanziani Oct 21 '13 at 13:30
  • I up voted you because this is a good question. I dislike it when people down vote because they probably think that it is a simple/ dumb question. What's so bad about it. good information was emitted. – jack blank Feb 21 '14 at 07:56

1 Answers1

1

According to the .serializeArray() API Documentation :

The .serializeArray() method uses the standard W3C rules for successful controls to determine which elements it should include; in particular the element cannot be disabled and must contain a name attribute.

So, having the name attribute is a must for .serializeArray().

palaѕн
  • 72,112
  • 17
  • 116
  • 136