Created
November 9, 2009 20:30
-
-
Save robinjfisher/230253 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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