FancyPrairie
Programmer
I've created a composite control consisting of a text box and list box. As the user types in the text box, the first item in the list box that matches what's in the text box is shown. The value in the text box is then updated to the highlighted value in the list box. This works fine.
For example, suppose I'm looking for Smith in the drop down list. When I type S, the first name that starts with S will be selected in the list box and displayed in the text box. Everything after the S (in the text box) is highlighted using the code below. Like this, S[COLOR=white black]ampson[/color]. If the next letter I type is M then it will find the first name that begins with SM (i.e. Sm[COLOR=white black]all[/color]).
Here's my problem. If the text box is sized so that the last part of the name is not shown (too small for name to fit), when I issue the range.select command, the name scrolls to the left. I believe what is causing it to scroll is when I issue the range.moveEnd command. For example,
range.moveStart(txtBox, 2);
range.moveEnd(txtBox, txtBox.value.length - 2);
range.select();
Is there a way to select a range without actually moving the cursor to a new location?
This is the routine I use to highlight from current position to end of line.
For example, suppose I'm looking for Smith in the drop down list. When I type S, the first name that starts with S will be selected in the list box and displayed in the text box. Everything after the S (in the text box) is highlighted using the code below. Like this, S[COLOR=white black]ampson[/color]. If the next letter I type is M then it will find the first name that begins with SM (i.e. Sm[COLOR=white black]all[/color]).
Here's my problem. If the text box is sized so that the last part of the name is not shown (too small for name to fit), when I issue the range.select command, the name scrolls to the left. I believe what is causing it to scroll is when I issue the range.moveEnd command. For example,
range.moveStart(txtBox, 2);
range.moveEnd(txtBox, txtBox.value.length - 2);
range.select();
Is there a way to select a range without actually moving the cursor to a new location?
This is the routine I use to highlight from current position to end of line.
Code:
function Highlight(input, selectionStart, length)
{
var range = input.createTextRange();
range.collapse(true);
range.moveStart('character', selectionStart);
range.moveEnd('character', length);
range.select();
}