/** * Steps: * * 1. Output a drupal select box by default so that if js is turned off the user would have a normal dropdown + submit form * 2. Give drupal a class of "jquery_dropdown" * 3. Have jquery convert it to a hidden input and hide the submit * 4. Have jquery grab all the key/values from the select build the css/html markup that 'looks' like a dropdown * 5. Add a listener so when an item gets selected and populate the hidden value and submit the form to achieve the same functionality * **/ $(document).ready(function() { //this does the actual css/html replacement of the select dropdown $("select.jquery_dropdown").each(function(){ $(this).load_jquery_dropdown();//load jquery dropdowns }); }); /** * Load jquery dropdown for a select * * This is a re-usable function for select elements that don't have the .jquery_dropdown class */ $.fn.load_jquery_dropdown = function(options) { if (!$(this).html() || $(this).hasClass('jquery_dropdown_processed')) return; $(this).hide();//hide this select //hide elements with jquery_dropdown class (in case you want to hide the submit button for instance) //for a better hide we have included .jquery_dropdown { display: none; } in the default css which keeps //the select from "flashing" on and off, the noscript tag inserted in hook_footer() keeps it from hiding //those elements when javascript is disabled to make it degrade gracefully $(".jquery_dropdown").hide(); var select_id = $(this).attr('id'); var select_name = $(this).attr('name'); var select_default_value = $(this).val(); var select_default_text = $(this).find('option[value='+select_default_value+']').text(); var select_values = new Array(); var c = 0; var output = '