function filterdependantDropdown(filteringField, first){ var filteredFieldName = filteringField.filteredName.replace("_","-"); var filteredField = document.getElementById("edit-"+filteredFieldName+"-keys"); var curr = filteredField.options[filteredField.selectedIndex].value; filteredField.options.length = 0; var ops = js_options[filteringField.options[filteringField.selectedIndex].value]; for (i in ops){ var opt = document.createElement('option'); opt.value = opt.text = ops[i]; try{filteredField.options.add(opt, null);} catch(ex) {filteredField.options.add(opt);} } if(first){ for (i=0; i < filteredField.options.length; i++){ if(filteredField.options[i].value==curr) filteredField.options[i].selected = true; } } } function dependantDropdownAutoAttach() { $('select.filteringField').each(function(){ this.filteredName = this.title; this.removeAttribute('title'); this.onchange = function(){ filterdependantDropdown(this, false);} filterdependantDropdown(this, true); } ); } if (Drupal.jsEnabled) $(document).ready(dependantDropdownAutoAttach);