Skip to content

Instantly share code, notes, and snippets.

@robinjfisher
Created November 9, 2009 20:30
Show Gist options
  • Save robinjfisher/230253 to your computer and use it in GitHub Desktop.
Save robinjfisher/230253 to your computer and use it in GitHub Desktop.
if($("plane_airport_id")) {
new Form.Element.Observer('plane_airport_id', 0.1, function(event) {
var string = $F('plane_airport_id');
if (string.length >= 3) {
new Ajax.Request('/airports', {method:'get',parameters:{search:string},
onSuccess: function(transport) {
var airports = transport.responseJSON;
var lis = $('airport-list').descendants();
if (lis.length > 0) {
lis.each(function(l) {
l.remove();
});
};
airports.each(function(a) {
var item = "<li class='airport'><a href='javascript:;' class='airport-link'>" + a + "</a></li>";
$('airport-list').insert(item);
});
$$('.airport-link').each(function(a) {
a.observe("click", function() {
var text = $(this).innerHTML;
Form.Element.setValue('plane_airport_id',text);
});
});
}
});
} else {
var lis = $('airport-list').descendants();
if (lis.length > 0) {
lis.each(function(l) {
l.remove();
});
};
};
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment