Forum Moderators: open
function edit(){
if(se.options[2]){
if(event.keyCode==8){
var str=se.options[2].innerText;
var len=str.length;
se.options[2].innerText=str.substring(0,len-1);
if(se.options[2].innerText=="")se.remove(2);
}
if(event.keyCode==13)return false;
if(event.keyCode==32){
se.options[2].innerText+=" ";
}
}
}
</script>
<select id=se onkeypress=pp() onkeyup="edit()">
<option>TEST
<option>javascript
</select>
YOU CAN INPUT LETTER
</td></tr>
</table></center>
<br>
<br>
<html>
<head>
<script type="text/javascript">
function listSearch(which) {
fontSearch = which.field.value;
if(event.keyCode==40 ¦¦ event.keyCode==34) {
// 40 = Pressed down key
// 34 = Pressed pgdn key
selNow = which.list.selectedIndex;
selMax = which.list.length - 1;
if(selNow!=0 && fontSearch!=which.list.options[selNow].value) {
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
else {
if(event.keyCode==40) {
which.list.selectedIndex = (selNow==selMax?selMax:selNow+1);
}
else if(event.keyCode==34) {
which.list.selectedIndex = (selNow>(selMax-10)?selMax:selNow+10);
}
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
}
else if(event.keyCode==38 ¦¦ event.keyCode==33) {
// 38 = Pressed up key
// 33 = Pressed pgup key
selNow = which.list.selectedIndex;
if(selNow!=0 && fontSearch!=which.list.options[selNow].value) {
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
else {
if(event.keyCode==38) {
which.list.selectedIndex = (selNow<2?1:selNow-1);
}
else if(event.keyCode=33) {
which.list.selectedIndex = (selNow<11?1:selNow-10);
}
which.field.value = which.list.options[which.list.selectedIndex].value;
which.field.focus();
which.field.select();
}
}
else if(fontSearch!="") {
regexp = new RegExp("^" + fontSearch, "i");
found = 0;
for(i=1; i<which.list.length; i++) {
listFont = which.list.options[i].value;
if(listFont.match(regexp)) {
found = i;
i = which.list.length;
}
}
which.list.selectedIndex = found;
}
else {
window.status=event.keyCode;
}
}
</script>
<style type="text/css">
body {
font: 10px Verdana;
}
form {
margin: 0;
}
fieldset {
border: 1px solid #999;
padding: 10px;
width: 500px;
}
legend {
color: #00c;
}
</style>
</head>
<body>
<fieldset>
<legend>Select Font</legend>
<form name="foobar">
<div>
My font:<br>
<input type="text" name="field" size="25" onkeypress="if(event.keyCode==8) { listSearch(this.form); }" onkeyup="listSearch(this.form)"><br>
<select name="list" size="1">
<option value="">Select font</option>
<option value="Algerian">Algerian</option>
<option value="Arial">Arial</option>
<option value="Arial Black">Arial Black</option>
<option value="Arial Narrow">Arial Narrow</option>
<option value="Courier">Courier</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Trebuchet MS">Trebuchet MS</option>
<option value="Verdana">Verdana</option>
</select><br>
<br>
<input type="button" value="Foobar">
</div>
</form>
</fieldset></body>
</html>
Type something in the input field, for example "arial narrow". Watch the select field as you type. Then delete the text, type something else, and so on.