$(function(){ var values = new Array(); $(document).on('change', '.form-group-multiple-selects .input-group-multiple-select:last-child select','.form-group-1', function(){ var selectsLength = $(this).parent().parent().find('.input-group-multiple-select select').length; var optionsLength = ($(this).find('option').length)-1; if(selectsLength < optionsLength){ var sInputGroupHtml = $(this).parent().html(); var sInputGroupClasses = $(this).parent().attr('class'); $(this).parent().parent().append('
'+sInputGroupHtml+'
'); } updateValues($(this).parent().parent()); }); $(document).on('change', '.form-group-multiple-selects .input-group-multiple-select:not(:last-child) select','.form-group-1', function(){ updateValues($(this).parent().parent()); }); $(document).on('click', '.input-group-addon-remove', function(){ var oSelectContainer = $(this).parent().parent() $(this).parent().remove(); updateValues(oSelectContainer); }); function updateValues(oSelectContainer){ values = new Array(); $(oSelectContainer).find('.input-group-multiple-select select').each(function(){ var value = $(this).val(); if(value != 0 && value != ""){ values.push(value); } }); $(oSelectContainer).find('.input-group-multiple-select select').find('option').each(function(){ var optionValue = $(this).val(); var selectValue = $(this).parent().val(); if(in_array(optionValue,values)!= -1 && selectValue != optionValue) { $(this).attr('disabled', 'disabled'); } else { $(this).removeAttr('disabled'); } }); } function in_array(needle, haystack){ var found = 0; for (var i=0, length=haystack.length;i 20 || document.documentElement.scrollTop > 20) { document.getElementById("myBtn").style.display = "block"; } else { document.getElementById("myBtn").style.display = "none"; } } // When the user clicks on the button, scroll to the top of the document function topFunction() { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera }