How to Create Custom CSS, jQuery Autocomplete Plugin

Web developers often use autocomplete features in websites as a part of their work. Yet lot of good jquery autocomplete plugins are available but if we want to create our own plugin then what to do. Actually when jquery libraries are conflicting with each other specially when page is heavily loaded with jquery, we think about some simple autocomplete plugin. I feel creating an autocomplete plugin is very simple to prevent the need of including another large javascript library.

This is a fully javascript autocomplete plugin:
Lets start :

The CCS

		#joyautocomplete li{list-style-type:none;cursor: pointer;padding:5px}
		#joyautocomplete{
		box-shadow: 1px 1px 1px 1px #ccc;
  
    margin-top: 0px;
    padding: 0px;}
	#joyautocomplete li:hover{background:rgba(150, 176, 181, 0.24)}

The JS

var people = ['Steven', 'Sean', 'Stefan', 'Sam', 'Nathan'];

function matchPeople(input) {
  var reg = new RegExp(input.split('').join('\\w*').replace(/\W/, ""), 'i');
  
  return people.filter(function(person) {
    if (person.match(reg)) {
      return person;
    }
  });
}


function changeInput(val) {
var inputwidth=document.getElementById('firm_name').offsetWidth;


 var autoCompleteResult = matchPeople(val);
 var list = '</pre>
<ul id="joyautocomplete">
 <li>' + autoCompleteResult.join('</li>
 <li>') + '</li>
</ul>
document.getElementById("result").innerHTML = list; document.getElementById('joyautocomplete').style.width=inputwidth; document.getElementById('joyautocomplete').onclick = function(event) { var target = getEventTarget(event); document.getElementById("firm_name").value = target.innerHTML; document.getElementById("joyautocomplete").style.display ='none' ; } } function getEventTarget(e) { e = e || window.event; return e.target || e.srcElement; }
<pre><input id="firm_name" style="width: 50%;" type="text" /></pre>
<div id="result"></div>

How to Create Custom CSS, jQuery Autocomplete Plugin

Web developers often use autocomplete features in websites as a part of their work. Yet lot of good …

How to Make Sticky Sidebar Using jQuery and CSS

Sticky sidebar is an essential part of web development. Not in all cases but for some cases where ou…

Selectors, Animation, and AJAX – jQuery Tutorial And Examples

By now I’m sure you have grasped at least the basics and simplicity of the jQuery library. Now it’s …

s3Slider jQuery Plugin & Tutorial

The s3Slider jQuery plugin is made by example of jd`s smooth slide show script. Usage: HTML: Sample …

jQuery Optimization: Avoid Unnecessary Selector

Common subexpression elimination is a common way to optimize any programming code. Doing unnecessary…

Fading Links Using jQuery: dwFadingLinks

Earlier this month, we posted a MooTools script that faded links to and from a color during the mous…