1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| $('#selectWrap > select').on('change', function(){
addselect($('input[type=radio][name=services]:checked').attr('value'), $(this).children('option:selected').attr('value'), $(this));
});
function addselect(service, parent, elt){
elt.nextAll("select").remove();
if ( elt.val() != '-1' ) {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: 'serviceId='+service+'&parentId='+parent+'&structures=ok',
dataType: 'json',
cache: false,
beforeSend: function(){
$("<img/>",{src: "assets/img/ajax-loader.gif", id: "loader"}).insertAfter(elt);
},
complete: function(){
$("#loader").remove();
},
success: function(data){
if ( data.result.children.length > 0 ) {
var items = data.result.children, level = data.result.level;
$('<select/>',{'class':'form-control'}).insertAfter(elt);
$('<option/>',{value: '-1', html: 'Choisir dans "' + elt.children('option:selected').text() + '"'}).appendTo($('#selectWrap > select').eq(-1));
for(var i in items){
$("<option/>",{value: items[i].struc_id, html: items[i].struc_name}).appendTo($('#selectWrap > select').eq(-1));
}
}
}
});
}
} |
Partager