What you want is really javascript if you mean do it in the browser. As noted you need a SORTED array of all the possiblities. Then you would do something like:
<head>
<script>
var elements = 6;
options = new Array();
options[0] = 'h';
options[1] = 'he';
options[2] = 'heat';
options[3] = 'hell';
options[4] = 'hello';
options[5] = 'hello world';
function inputDelta() {
var index = -1;
var search = someform.search.value;
if ( search == '' ) {
someform.guess.value = search;
return 1;
}
var re = new RegExp(search);
for( i = 0; i < elements; i++ ) {
if ( options[i] == search ) {
break;
}
if ( options[i].match(re) ) {
index = i;
}
}
if ( index != -1 ) {
someform.guess.value = options[index];
}
else {
someform.guess.value = search;
}
return 1;
}
</script>
</head>
<body onLoad="javascript:someform.search.select();someform.search.focu
+s()">
<form name="someform">
<input type="text" name="search" value="Type Search Here"
onChange="inputDelta()" onKeyup="inputDelta()" onBlur="inputDelta()">
+<br>
<input type="text" name="guess" value="">
</form>
Note that this is a horrendously inefficient algorithm in that it iterates through a sorted list every time. See File::SortedSeek for a Perl implementation of the binary tree/split the difference algorithm. Have fun implementing it in javascript! If the list of possibilities is large you would put it in a .js file and include it to save the download overhead (if you have repeat access issues)
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|