tom_gosling
07-30-2004, 10:50 AM
Hi,
I'm creating an auto-complete text box which searches values from an array. So for instance if you enter "a", "apple" will come up. If you enter "at", attention will come up and so on.
So after "a" has been entered, I need the rest of the following characters to be selected so that if the user then wants to enter "at" all they have to do is press the "t" key instead of having to delete the following characters manually and then enter "t". See what I mean?
So, I've go the cursor position and I'm looping through the rest of the characters and trying to select each one as I go. This is where the problem is.
Does anyone know how to select individual characters or sub-strings? It would be most appreciated.
Many thanks in anticipation!
Tom
function findAirport(field,keycode){
kc = new Array();
var good=0;
var pos=0;
var cursorPos = GetCaretPos(field);
if(((keycode>=65)&&(keycode<=90))||((keycode>=97)&&(keycode<=122))){good=1;}
if(good==0){return;}
for(i=0;i<airport_id.length;i++){
pos = airport_name[i].indexOf(field.value.toUpperCase());
if(pos==0){
field.value = airport_name[i];
break;
}
}
// PLEASE HELP WITH THIS BIT (You can see what I'm trying to do)
for(i=cursorPos;i<field.value.length;i++){
field.value.charAt(i).select();
}
}
I'm creating an auto-complete text box which searches values from an array. So for instance if you enter "a", "apple" will come up. If you enter "at", attention will come up and so on.
So after "a" has been entered, I need the rest of the following characters to be selected so that if the user then wants to enter "at" all they have to do is press the "t" key instead of having to delete the following characters manually and then enter "t". See what I mean?
So, I've go the cursor position and I'm looping through the rest of the characters and trying to select each one as I go. This is where the problem is.
Does anyone know how to select individual characters or sub-strings? It would be most appreciated.
Many thanks in anticipation!
Tom
function findAirport(field,keycode){
kc = new Array();
var good=0;
var pos=0;
var cursorPos = GetCaretPos(field);
if(((keycode>=65)&&(keycode<=90))||((keycode>=97)&&(keycode<=122))){good=1;}
if(good==0){return;}
for(i=0;i<airport_id.length;i++){
pos = airport_name[i].indexOf(field.value.toUpperCase());
if(pos==0){
field.value = airport_name[i];
break;
}
}
// PLEASE HELP WITH THIS BIT (You can see what I'm trying to do)
for(i=cursorPos;i<field.value.length;i++){
field.value.charAt(i).select();
}
}