Created
June 14, 2012 12:21
-
-
Save cfjedimaster/2929966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/wingwan/5813874