...

View Full Version : autocomplete question



bootcom
10-13-2005, 10:18 AM
Hi,

I've recently got a hold of a function that allows for predictive / autocomplete text (shown below). This is fine when Im using it on the first word, however what I'm trying to do is to get it on anything after the first word (ie the second or third word in the text box). If anyone could give some pointers I would be much obliged.

Cheers

function autoComplete (dataArray, input, evt) {

if (temp.length == 0) {
return;
}
var match = false;
for (var i = 0; i < dataArray.length; i++) {
if ((match = dataArray[i].toLowerCase().indexOf
(temp.toLowerCase()) == 0)) {
break;
}
}
if (match) {
var typedText = input.value;
if (typeof input.selectionStart != 'undefined') {
if (evt.keyCode == 16) {
return;
}
input.value = dataArray[i];
input.setSelectionRange(typedText.length, input.value.length);
}
else if (input.createTextRange) {
if (evt.keyCode == 16) {
return;
}
input.value = dataArray[i];
var range = input.createTextRange();
range.moveStart('character', typedText.length);
range.moveEnd('character', input.value.length);
range.select();
}
else {
if (confirm("Are you looking for '" + dataArray[i] + "'?")) {
input.value = dataArray[i];
}
}
}
}

rm-f
10-14-2005, 07:34 PM
maybe:

if ((match = dataArray[i].toLowerCase().indexOf(temp.toLowerCase()) >= 0)) {

so it doesn't need to be found at the very beginning

bootcom
10-15-2005, 07:33 AM
Unfortunately,

it still only looks for the first word in the input. Everything else is ignored :eek:

vwphillips
10-15-2005, 09:33 AM
Method to autocomplete the end text is to split the text input at the spaces and examine the charactors after the last space for a match.

If matched, replace the text with current text less the charactors after the last space plus the matched word.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum