1 $(document).ready(function() {
2 $("#desk_id").children().each(function() {
3 var selectedBranch = $("#branch"). children("option:selected"). val();
4 if ($(this).attr('id') === "nodesk") { //set no desk by default, should be first element
5 $(this).prop("selected", true);
6 $(this).prop("disabled", false);
9 else if ($(this).hasClass(selectedBranch)) {
10 $('#nodesk').prop("disabled", true); // we have desk, no need for nodesk option
12 $(this).prop("disabled", false);
14 $(this).prop("selected", true)
16 $(this).prop("disabled", true);
21 $("#branch").on("change", function() {
23 $("#desk_id").children().each(function() {
24 var selectedBranch = $("#branch"). children("option:selected"). val();
25 if ($(this).attr('id') === "nodesk") { //set no desk by default, should be first element
26 $(this).prop("selected", true);
27 $(this).prop("disabled", false);
30 else if ($(this).hasClass(selectedBranch)) {
31 $('#nodesk').prop("disabled", true); // we have desk, no need for nodesk option
33 $(this).prop("disabled", false);
35 $(this).prop("selected", true)
37 $(this).prop("disabled", true);