Dimitri Danilov Dimitri Danilov - 1 month ago 7
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>
</div>
</div>
</div>


When I submit the data I do this :

console.log($("#meta-keyword").length);
var unindexed_array = $form.serializeArray();
console.log(unindexed_array);


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

However, I find my input with the id
description
.

Have any idea why ?

Answer

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

Comments