Skip to content

Instantly share code, notes, and snippets.

@tamboer
Last active December 16, 2015 19:39
Show Gist options
  • Select an option

  • Save tamboer/5487176 to your computer and use it in GitHub Desktop.

Select an option

Save tamboer/5487176 to your computer and use it in GitHub Desktop.
jQuery ajax to get staff from selected department
$(document).ready(function(){
$date_from = $('#date_from').val();$date_to = $('#date_to').val();$source = '';
$('#teamSelector').change(function(){
$selected_team = $(this).val();
$.ajax({
url : $baseUrl + "/public/staff/staff/return-json-staff",
type : "POST",
data : 'selected_team='+$selected_team+'&date_from='+$date_from+'$date_to='+$date_to+'&source='+$source
}).done(function($response){
var obj = jQuery.parseJSON($response);
$element = $('<select name="staff" id="staff">');
$element.append('<option value="all"></option>');
for(var x in obj){
console.log(x)
$element.append('<optgroup label="' + x + '">');
for(var y in obj[x]){
$element.append('<option value="' + y + '">' + obj[x][y] + '</option>')
}
$element.append('</optgroup>');
}
$element.append('</select>');
$('#staffSelectContainer').html($element);
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment