Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created June 14, 2012 12:21
Show Gist options
  • Save cfjedimaster/2929966 to your computer and use it in GitHub Desktop.
Save cfjedimaster/2929966 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Example 1</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#search").on("input", function(e) {
var val = $(this).val();
if(val === "") return;
//You could use this to limit results
//if(val.length < 3) return;
console.log(val);
$.get("artservice.cfc?method=getart&returnformat=json", {term:val}, function(res) {
var dataList = $("#searchresults");
dataList.empty();
if(res.DATA.length) {
for(var i=0, len=res.DATA.length; i<len; i++) {
var opt = $("<option></option>").attr("value", res.DATA[i][0]);
dataList.append(opt);
}
}
},"json");
});
})
</script>
</head>
<body>
<p>
<input type="text" name="search" id="search" placeholder="Type Something" list="searchresults" autocomplete="off">
<datalist id="searchresults"></datalist>
</p>
</body>
</html>
@wingwan
Copy link

wingwan commented Jun 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment