$(document).ready(function(){
deflectEvent = function(event) {
var noOfListItems = $("#select > option").length-1;
var curListItem = $("#select")[0].selectedIndex;
if(event.which == $.ui.keyCode.UP) {
// Decrement the selection by one, unless that will be less than zero, then go to the last option
var nextListitem = (curListItem-1 < 0) ? noOfListItems : curListItem-1;
$("#select")[0].selectedIndex = nextListitem;
//$("input")[0].val($("#select")[0].val);
console.log($("#select").val());
$("input").val($("#select").val());
}
if(event.which == $.ui.keyCode.DOWN){
// Increment the selection by one, unless that will be more than the number of options, then go to the first option
var nextListitem = (curListItem+1 > noOfListItems) ? 0 : curListItem+1;
$("#select")[0].selectedIndex = nextListitem;
$("input").val($("#select").val());
}
}
jQuery(function($){
$('#input').bind('keydown',deflectEvent);
$('#select').bind('change',function(){
$("input").val($("#select").val());
});
});
//jQuery(function($){$('#input').bind('change',searchSelect)});
https://jsfiddle.net/user/fiddles/all/
searchBox = document.querySelector("#input");
selectBox = document.querySelector("#select");
var current = 0;
searchBox.addEventListener("keydown", function (e) {
var text = e.target.value; //searchBox value
var options = selectBox.options; //select options
for (var i = 0; i < options.length; i++) {
var option = options[i]; //current option
var optionText = option.text; //option text ("Somalia")
var lowerOptionText = optionText.toLowerCase(); //option text lowercased for case insensitive testing
var lowerText = text.toLowerCase(); //searchBox value lowercased for case insensitive...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.