Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brahimmachkouri/c396dc31843fa513aa33 to your computer and use it in GitHub Desktop.
Save brahimmachkouri/c396dc31843fa513aa33 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
var myJson = new Array();
$(document).ready(function() {
// Pas en asynchrone pour le dev (debug)
/*$.ajaxSetup({
async: false
});
*/
// Recupère les infos au format JSON et remplit la select etablissement avec les infos adéquates
$.getJSON( "{{url_base}}jsoninfos/", function( data ) {
myJson = data;
});
// Remplit "dynamiquement" la select des formations en fonction de l'établissement choisit
$('#etablissement').on('change', function() {
for(var i = 0; i < myJson.length; i++) {
if(myJson[i].id == $(this).val()) {
$('#formation').html('<option value="0">Selectionnez formation</option>');
$.each(myJson[i].formations, function (index, formation) {
$("#formation").append('<option value="'+formation.id+'">'+formation.for_nom+'</option>');
});
}
}
});
});
</script>
/*
Example of JSON for this script :
[
{
"id":"1",
"etab_nom":"IUT DE TRUC",
"formations":[
{
"id":"5",
"for_nom":"LICENCE PRO URBANISME",
},
{
"id":"98",
"for_nom":"D.U. GEST. OPER. LOGIST.",
}
]
},
{
"id":"2",
"etab_nom":"CENTRE UNIVERSITAIRE LETTRES",
"formations":[
{
"id":"67",
"for_nom":"LICENCE ANGLAIS",
},
{
"id":"78",
"for_nom":"LICENCE ESPAGNOL",
}
]
},
{
"id":"3",
"etab_nom":"CENTRE UNIVERSITAIRE CHIMIE",
"formations":[
{
"id":"90",
"for_nom":"LICENCE BIOCHIMIE",
},
{
"id":"68",
"for_nom":"LICENCE CHIMIE ORGANIQUE",
}
]
}
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment