Skip to content

Instantly share code, notes, and snippets.

@thotbox
Last active August 29, 2015 14:03
Show Gist options
  • Save thotbox/258ab7dcf990669e1fff to your computer and use it in GitHub Desktop.
Save thotbox/258ab7dcf990669e1fff to your computer and use it in GitHub Desktop.
JavaScript: Combo Box Search
// Combo Box
$(document).ready(function() {
$('#providers li').click(function(e) {
$('#provider').val($(this).text()).change();
setTimeout(function () {
$('#provider-list').hide();
}, 300);
});
$('#provider').blur(function() {
setTimeout(function () {
$('#provider-list').hide();
}, 300);
});
});
// Subscribe Filter
$('#provider').keyup(function() {
var filter = $(this).val();
if ( filter !== '' ) {
$('#provider-list').show();
}
$('#providers li').each(function() {
if ($(this).text().search(new RegExp(filter, 'i')) < 0) {
$(this).hide();
} else {
$(this).show();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment