Skip to content

Instantly share code, notes, and snippets.

@bengrosser
Created March 1, 2016 22:39
Show Gist options
  • Save bengrosser/fad5fac874c269161a87 to your computer and use it in GitHub Desktop.
Save bengrosser/fad5fac874c269161a87 to your computer and use it in GitHub Desktop.
aNzrwm
<form method="get" id="search">
<input type="text" class="searchbox" value="Search Wikipedia..." onblur="if(this.value == '') { this.value = 'Search Wikipedia...'; }" onfocus="if(this.value == 'Search Wikipedia...') { this.value = ''; }" name="s">
<button type="submit">Submit</button>
</form>
$(".searchbox").autocomplete({
source: function(request, response) {
$.ajax({
url: "http://en.wikipedia.org/w/api.php",
dataType: "jsonp",
data: {
'action': "opensearch",
'format': "json",
'search': request.term
},
success: function(data) {
response(data[1]);
}
});
}
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment