bssanchez93

Jquery Autocomplete Example

Sep 16th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>prueba</title>
  5.         <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  6.         <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  7.         <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  8.         <link rel="stylesheet" href="/resources/demos/style.css" />
  9.         <script>
  10.             $(function() {
  11.                
  12.                  $("#tags").autocomplete({
  13.                     source : function( request , response ){
  14.                         var url = "autocomplete.php";
  15.                         $.post(url, { 'search' : request.term }, response, 'json');
  16.                     },
  17.                     select: function( event, ui ) {
  18.                         $("#tags").val(ui.item.name);
  19.                         //$('#hidden_tag').val(ui.item.name);
  20.  
  21.                          return false;
  22.                     }
  23.                 }).data("ui-autocomplete")._renderItem = function(ul, item) {
  24.                         return $("<li>").append( "<a>" + item.name + "</a>" ).appendTo( ul );
  25.                 };        
  26.           });
  27.         </script>
  28.     </head>
  29.     <body>
  30.         <div class="ui-widget">
  31.             <input type="hidden" id="hidden_tag" name="hiddentag" value="">
  32.             <label for="tags2">Tags: </label>
  33.             <input type="text" id="tags" />
  34.         </div>      
  35.     </body>
  36. </html>
  37.  
  38. <!-- y el autocomplete.php -->
  39.  
  40. <?php
  41.     $data=array(array('name'=>'prueba'), array('name'=>'prueba2'));
  42.     echo json_encode($data);
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment