I have an index sortet alphabeticly, and I want a way to press on the 'g' key, and get to letter g. But I also have a search field, where i can write a word and search.
i have this code
Code:
 
<script>
 
function keyCapture()
{
 
if ( document.tekstsok.sokestreng.value.length != 0 )
{
return;
}
 
 
var bokstaver = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m",...) 
var tall = new Array("65", "66", "67", "68","69","70","71","72","73","74","75","76","77","78","79",...)
var i 
var x
x=30
 
if (event.keyCode == 32) {
location.href="#top";
event.returnValue=false; 
}
for (i=0; i < bokstaver.length; i++)
{
if (event.keyCode == tall[i])
	{
	x=i
	}
} 
if ( x < 29 ) { 
location.href="#" + bokstaver[x];
	 }
event.returnValue=false; 
}
 
</script> 
 
<body onKeyUp='keyCapture()'>
sokestreng is the search input field, so I check if that field has lenght != 0
But is there a way to check if the input field has focus or something? Because if I type something in the search field, but not submit, but deside to jump to 'g' instead, this will not work since length < 0