Skip to content

Instantly share code, notes, and snippets.

@gogogarrett
Created July 11, 2012 20:15
Show Gist options
  • Save gogogarrett/3093033 to your computer and use it in GitHub Desktop.
Save gogogarrett/3093033 to your computer and use it in GitHub Desktop.
$("#name").keyup(function() {
var s = $(this).val(),
url = "<%= recipient_search_path %>";
if ( s.length > 2 || s.length == 0 ) {
$.post( url, { s: s }, function( data ) {
if ( s.length == 0 ) {
$("#recipients").find('option').show();
}
else {
$("#recipients").find('option').hide();
}
if ( data.length == 0 ) {
$("#results").html(" ");
$("#results").html("No options found.");
}
$.each(data, function(key, value) {
$('#recipients option[value="' + value.id + '"]').show();
// $("#recipient_ids").append("<option value=" + value.id + ">" + value.first_name + ", " + value.last_name + "</option>");
})
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment