Dimitri Danilov Dimitri Danilov - 1 year ago 42
jQuery Question

serializeArray cannot find some inputs

I have this html structure :

<div class="col-md-12">
<div class="form-group">
<label>Mini description (affichage dernières destinations ajoutées et meta description)</label>
<textarea class="form-control" id="description" name="description"></textarea>
<div class="metadata">
<label>Titre de la page</label>
<input class="form-control" id="title" type="text"></input>
<label>Titre meta</label>
<input class="form-control" id="meta-title" type="text"></input>

When I submit the data I do this :

var unindexed_array = $form.serializeArray();

The first console log shows 1, but I cannot find my input in

However, I find my input with the id

Have any idea why ?

Answer Source

You don't have name on some inputs

Without a name they can't be submitted in a form and therefore won't be serialized by serialize() or serlizeArray()

name is what is used as the key for key/value pair