Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var input = $('.studentName');
  2. var hidden = $('.id');
  3. var autocomp = $('.autocomp');
  4.  
  5. function loadAutocomplete(html) {
  6.     var leftPos = input.position().left + 'px';
  7.     var topPos = (input.position().top + input.outerHeight()) + 'px';
  8.     var width = (input.outerWidth() + 10) + 'px';
  9.    
  10.     autocomp.css({
  11.         'left': leftPos,
  12.         'top': topPos,
  13.         'width': width
  14.     }).html(html);
  15. }
  16.  
  17. input.blur(function() {
  18.     setTimeout(function () {
  19.         autocomp.hide();
  20.     }, 200);
  21. });
  22.  
  23. input.focus(function() {
  24.     if (input.val() != '') {
  25.         autocomp.show();
  26.     }
  27. })
  28.  
  29. input.keyup(function() {
  30.     var term = input.val();
  31.     if (term == '') {
  32.         autocomp.hide();
  33.     }
  34.     $.get('test.php', {'q': term}, function(data) {
  35.         loadAutocomplete(data);
  36.         autocomp.show();
  37.     });
  38.     return false;
  39. });
  40.  
  41. function pickItem(id, name) {
  42.     autocomp.hide();
  43.     hidden.val(id);
  44.     input.val(name);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement