Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>autocomplete question

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.


 

TOP

For more info

setting a minimum size
Auto Preview of Image 
Refresh with a query s
JS Validation obsolete
Javascript Pop up func
Slide show transitions
I'm a newbie...please!
how to write coding in
Advanced Debug Info 
.js file doesn't work 

News Archive

Adding Graphic To Text
re-direct form after s
pop up window controls
Clock on homepage - He
passing a param from a
Password Procection wi
document.title in same
focus onload 
Counting Wrong from Ri
Help needed on how to 

Related stories:

Carriage Return FOR Javascript Code
Modifier key recognised with an ahref/onClick event?
getElementById won't work on Personal Computer
count subfolders and pass on values of array length to other page?
Validate Form Field
just some thoughts about new Date() object
How can i write javascript for server controls?
Dynamically creating variables.

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics