mercredi 28 janvier 2015

checkbox name[] to jquery $.ajax

Why my checkboxes:checked don't return nothing? When I check the items stated below, and then submit the form (with preventDefault()), they have an 'error_class' added, instead of having it removed. While the rest of my other inputs behave normally if they're not empty.



<label class="label" id="label_contrat">Type de contrat recherché</label>
<input type="checkbox" name="contrat[]" value="CDI" class="contrat_checkbox" tabindex="113"> <label for="CDI" class="tag_contrat">CDI</label>
<input type="checkbox" name="contrat[]" value="CDD" class="contrat_checkbox" tabindex="114"> <label for="CDD" class="tag_contrat">CDD</label>
<input type="checkbox" name="contrat[]" value="Interim" class="contrat_checkbox" tabindex="115"> <label for="Interim" class="tag_contrat">Interim</label> <br />
<input type="checkbox" name="contrat[]" value="Saisonnier" id='saison_c' class="contrat_checkbox" tabindex="116"> <label for="Saisonnier" class="tag_contrat">Emploi Saisonnier</label>
<input type="checkbox" name="contrat[]" value="Autres" class="contrat_checkbox" tabindex="117"> <label for="Autres" class="tag_contrat">Autres</label>



<input type="checkbox" name="cgu_inscription" id="cgu_inscription" tabindex="140"/>
<label class="label" id='label_cgu'>J'accepte les <a href="#" id="CGU_link">CGU</a></label>



/* var contrat = []
$("input[name='contrat[]']:checked").each(function ()
{
contrat.push(parseInt($(this).val()));
});*/

var contrat = { 'contrat[]' : []};
$("input[name='contrat[]']:checked").each(function() {
contrat['contrat[]'].push($(this).val());
});

var cgu_inscription = $("#cgu_inscription:checked").val();


$.ajax({
type : 'POST',
url : "process.php",
data: {myOtherValues:myOtherValues, contrat:contrat, cgu_inscription:cgu_inscription}
}, dataType:"json"
})
.done(function(data) { }
// etc




Aucun commentaire:

Enregistrer un commentaire