Skip to content

Instantly share code, notes, and snippets.

@impronunciable
Forked from ignacioricci/select-to-dropdown.js
Created February 6, 2012 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save impronunciable/1754093 to your computer and use it in GitHub Desktop.
Save impronunciable/1754093 to your computer and use it in GitHub Desktop.
Change select to dropdown list
var select_to_dropdown = function(el, dropdown, select_text ){
$(el).children().hide();
var sel_list = $('<div id="'+dropdown+'"><strong class="cta"><span></span></strong><ul></ul></div>');
sel_list.find('span').text($(el + ' label').text());
$(el + ' select').children('option').each(function(){
sel_list.children('ul').append('<li>' + $(this).text() + '</li>');
});
$(el).append(sel_list);
$(dropdown).find('li').live('click',function(e){
$(el + ' select option').eq($(this).index()).attr('selected','selected').siblings('option').removeAttr('selected');
$(this).addClass('selected');
$(this).siblings().removeClass();
$(dropdown + ' strong span').text($(this).text());
$(this).parent().slideUp('slow');
$('input[name="'+select_text+'"]').val($(this).text());
});
$(dropdown + ' strong').live('click',function(e){
e.preventDefault();
$(dropdown + ' ul').slideToggle('slow');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment