<html>
<head>
<style type="text/css">
ul { margin:0; padding:0; list-style-type:none }
div#suggests
{
margin:0;
overflow-y:auto;
height:96px;
width:145px;
border:1px solid #000;
display:block;
}
div#suggests a:link
{
color:#000;
line-height:19px;
width:100%;
text-decoration:none;
font-size:12px;
font-family:Verdana;
display:block;
}
div#suggests a:visited
{
color:#000;
line-height:19px;
width:100%;
text-decoration:none;
font-size:12px;
font-family:Verdana;
display:block;
}
div#suggests a:hover
{
color:#FFF;
line-height:19px;
width:100%;
text-decoration:none;
font-size:12px;
font-family:Verdana;
background-color:#39F;
display:block;
}
div#suggests a:active
{
color:#000;
line-height:19px;
width:100%;
text-decoration:none;
font-size:12px;
font-family:Verdana;
display:block;
}
</style>
<script type="text/javascript">
function eventHandling(element,type,callBack,returnParams)
{
var returnParams = returnParams;
if(document.addEventListener)
{
if(type.match(/^on/)) type = type.replace(/^on/,"");
element.addEventListener(type,handleEvent,false);
}
else // IE
{
if(!type.match(/^on/)) type = "on"+type;
element.attachEvent(type,handleEvent);
}
function handleEvent (evt)
{
var event = (evt)?evt:(window.event)?window.event:'';
if(event.stopPropagation)
{
event.stopPropagation();
}
else
{
event.cancelBubble = true;
}
var target = event.srcElement || event.currentTarget;
callBack.call(callBack,event,target,(returnParams)?returnParams:null);
}
}
function keynavigation (obj)
{
var curElement = null;
var naviElement = null;
function clearSpaces (strOut)
{
strOut = strOut.replace(/>\s+/gm, '>');
strOut = strOut.replace(/\s+</gm,'<');
strOut = strOut.replace(/>\s+</gm,'><');
return strOut;
}
function keyPressed (evt)
{
var curKey = evt.keyCode;
var div_id = document.getElementById('suggests');
var txt_id = document.getElementById('eingabe');
switch (curKey)
{
case 38:
if(curElement && curElement.previousSibling)
{
if(curElement.nextSibling)
{
div_id.scrollTop-=19; // Div scrollen, erst ab vorletztem Element
}
curElement = curElement.previousSibling;
txt_id.value = curElement.firstChild.id;
curElement.firstChild.style.color = '#FFF';
curElement.firstChild.style.backgroundColor = '#39F';
div_id.onmouseover = function style_weg()
{ // bei Mouseover im Div den Hovereffekt von Tastaturauswahl löschen
curElement.firstChild.style.color = curElement.firstChild.style.backgroundColor = '';
}
// Hovereffekt vom zuletzt markierten Element löschen
curElement.nextSibling.firstChild.style.color = curElement.nextSibling.firstChild.style.backgroundColor = '';
}
break;
case 40:
if(curElement)
{
if(curElement.nextSibling)
{
if(curElement.previousSibling)
{
var pos = div_id.scrollTop+=19; // Div scrollen, erst ab zweitem Element
}
curElement = curElement.nextSibling;
txt_id.value = curElement.firstChild.id;
curElement.firstChild.style.color = '#FFF';
curElement.firstChild.style.backgroundColor = '#39F';
div_id.onmouseover = function style_weg()
{ // bei Mouseover im Div den Hovereffekt von Tastaturauswahl löschen
curElement.firstChild.style.color = curElement.firstChild.style.backgroundColor = '';
}
// Hovereffekt vom zuletzt markierten Element löschen
curElement.previousSibling.firstChild.style.color = curElement.previousSibling.firstChild.style.backgroundColor = '';
}
}
else
{
curElement = naviElement.firstChild;
txt_id.value = curElement.firstChild.id;
curElement.firstChild.style.color = '#FFF';
curElement.firstChild.style.backgroundColor = '#39F';
}
break;
case 13:
if(curElement)
{
div_id.style.visibility = 'hidden';
//txt_id.focus();
}
break;
case 27:
{
div_id.style.visibility = 'hidden';
}
break;
default: return;
}
}
this.init = function ()
{
eventHandling(document,"keydown",keyPressed);
obj.innerHTML = clearSpaces (obj.innerHTML);
naviElement = obj;
}
}
window.onload = function () {
var k = new keynavigation(document.getElementById('sug_list'));
k.init();
}
</script>
<script type="text/javascript">
function insert_eingabe(id, eingabe)
{
document.getElementById(eingabe).value = id;
document.getElementById('suggests').style.visibility = 'hidden';
}
</script>
</head>
<body>
<form method="POST" action="">
<input type="text" id="eingabe"><input type="submit" value="OK">
<div id="suggests">
<ul id="sug_list">
<li><a id="id_eins" onclick="insert_eingabe(id, 'eingabe')" href="#">Eins</a></li>
<li><a id="id_zwei" onclick="insert_eingabe(id, 'eingabe')" href="#">Zwei</a></li>
<li><a id="id_drei" onclick="insert_eingabe(id, 'eingabe')" href="#">Drei</a></li>
<li><a id="id_vier" onclick="insert_eingabe(id, 'eingabe')" href="#">Vier</a></li>
<li><a id="id_fuenf" onclick="insert_eingabe(id, 'eingabe')" href="#">Fuenf</a></li>
<li><a id="id_sechs" onclick="insert_eingabe(id, 'eingabe')" href="#">Sechs</a></li>
<li><a id="id_sieben" onclick="insert_eingabe(id, 'eingabe')" href="#">Sieben</a></li>
<li><a id="id_acht" onclick="insert_eingabe(id, 'eingabe')" href="#">Acht</a></li>
<li><a id="id_neun" onclick="insert_eingabe(id, 'eingabe')" href="#">Neun</a></li>
<li><a id="id_zehn" onclick="insert_eingabe(id, 'eingabe')" href="#">Zehn</a></li>
<li><a id="id_elf" onclick="insert_eingabe(id, 'eingabe')" href="#">Elf</a></li>
<li><a id="id_zwoelf" onclick="insert_eingabe(id, 'eingabe')" href="#">Zwoelf</a></li>
</ul>
</div>
</form>
</body>
</html>