vendredi 23 janvier 2015

Jquery split variable back from PHP json (checkbox:checked)

In this code jquery get the data back from php and i would like to get jquery explode one of the variable where multiple auto are stored and finally get the specific checkbox checked


json_reponse_from_PHP: "auto1; auto3; auto4".



$(document).on("click", "#update", function(e) {
e.preventDefault();
var datas = 'pg/post.php';
$.getJSON(datas, function(data) {
$.each(data, function( key, value ) {
$('input[name='+key+'], select[name='+key+'], textarea[name='+key+']').val(value);
});
});
});

<div>
<input type="text" name="name" value="" />
<input type="text" name="name" value="" />
</div>


See example:



<input type="checkbox" name="auto[]" checked="checked" value="auto1" />
<input type="checkbox" name="auto[]" value="auto2" />
<input type="checkbox" name="auto[]" checked="checked" value="auto3" />
<input type="checkbox" name="auto[]" checked="checked" value="auto4" />
<input type="checkbox" name="auto[]" value="auto5" />
<input type="checkbox" name="auto[]" value="auto6" />


Can you help me to find





Aucun commentaire:

Enregistrer un commentaire