Click to See Complete Forum and Search --> : Selecting substrings within text boxes


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();
}
}

simpson97
07-31-2004, 01:28 AM
Check this:
http://www.devguru.com/Technologies/ecmascript/quickref/evhan_onKeyPress.html

Bob

tom_gosling
08-02-2004, 03:28 AM
Thanks Bob but no help there I'm afraid.

I need to know if it's possible to dynamically select seperate characters within the textbox/input.

Tom

vwphillips
08-02-2004, 07:16 AM
Nt much time at the moment but I have an auto select(due another update) It may have the answer to your question Til i can give it more time

http://homepage.ntlworld.com/vwphillips/TextBoxSelect/TextBoxSelect.htm

if you answer this I will be able to find the post again again