Learn

Auto complete Input Field with Data using Jquery

Jquery Auto Complete
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Hello Guys,

I am going to show a method to auto-complete your input fields with some data. The first thing you need to do is store your all the data in a jQuery array. Example

<script>
$(function() {
var list= [
“Asp”,
“Apple”,
“Ant”,
“BASIC”,
“C”,
“Clojure”,
“ColdFusion”,
“Erlang”,
“Fortran”,
“Groovy”,
“Haskell”,
“Java”,
“Lisp”,
“Perl”,
“PHP”,
];

});
</script>

Once you done with the an array. Now simply make a function to call every thing in your input box. Example

<script>

$(function() {
$( “#populate_list” ).autocomplete({
source: list // list is the variable that we declare on the top and save our array in it.
});
});
</script>

After declaring the function now move to the next step and create a simple input field with the id “populate_list” as we area calling autocomplete function on that id.

<input id=”populate_list”>

Here is full page code. you can copy, paste and use it as per your requirments.

<!doctype html>
<html lang=”en”>
<head>
<meta charset=”utf-8″>
<title>My Autocomplete Script</title>
<link rel=”stylesheet” href=”//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css”>
<script src=”//code.jquery.com/jquery-1.10.2.js”></script>
<script src=”//code.jquery.com/ui/1.11.4/jquery-ui.js”></script>

<script>
$(function() {
var list= [
“Asp”,
“Apple”,
“Ant”,
“BASIC”,
“C”,
“Clojure”,
“ColdFusion”,
“Erlang”,
“Fortran”,
“Groovy”,
“Haskell”,
“Java”,
“Lisp”,
“Perl”,
“PHP”,
];

$( “#populate_list” ).autocomplete({
source: list // list is the variable that we declare on the top and save our array in it.
});

});
</script>

</head>
<body>

<div class=”ui-widget”>
<input id=”populate_list”>
</div>

</body>
</html>

Please do not forget to add the jQuery CDN files as they are important to run this script.

Enjoy!

If you have any question. Feel free to write or comment.


  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Most Popular

To Top