JqueryUI - The Autocomplete widgets provides suggestions while you type into the field


SUBMITTED BY: jlolk3r

DATE: Jan. 28, 2016, 2:46 a.m.

FORMAT: HTML

SIZE: 1.9 kB

HITS: 1048

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Autocomplete - Remote JSONP datasource</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  8. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="/resources/demos/style.css">
  10. <style>
  11. .ui-autocomplete-loading {
  12. background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat;
  13. }
  14. #city { width: 25em; }
  15. </style>
  16. <script>
  17. $(function() {
  18. function log( message ) {
  19. $( "<div>" ).text( message ).prependTo( "#log" );
  20. $( "#log" ).scrollTop( 0 );
  21. }
  22. $( "#city" ).autocomplete({
  23. source: function( request, response ) {
  24. $.ajax({
  25. url: "http://gd.geobytes.com/AutoCompleteCity",
  26. dataType: "jsonp",
  27. data: {
  28. q: request.term
  29. },
  30. success: function( data ) {
  31. response( data );
  32. }
  33. });
  34. },
  35. minLength: 3,
  36. select: function( event, ui ) {
  37. log( ui.item ?
  38. "Selected: " + ui.item.label :
  39. "Nothing selected, input was " + this.value);
  40. },
  41. open: function() {
  42. $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
  43. },
  44. close: function() {
  45. $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
  46. }
  47. });
  48. });
  49. </script>
  50. </head>
  51. <body>
  52. <div class="ui-widget">
  53. <label for="city">Your city: </label>
  54. <input id="city">
  55. Powered by <a href="http://geonames.org">geonames.org</a>
  56. </div>
  57. <div class="ui-widget" style="margin-top:2em; font-family:Arial">
  58. Result:
  59. <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
  60. </div>
  61. </body>
  62. </html>

comments powered by Disqus