Hi
I'm developing a webpart to search for customers etc., but that is not really the important part.
I'm using an UpdatePanel and need some sort of AutoComplete behavior, nothing advanced or anything. Just a list/table of results that is updated as the user changes the text in the input field. For this I'm using the onKeyUp event to catch keystrokes. But the postback behavior steals focus from the textbox so i use TextBox.Focus() method to set this (could not get at client script to work). This gives focus back to the TextBox but leaves the cursor at the beginning of the field. I then use another client script top change the position of the cursor to the end. This works great, but if you type to fast sometimes it has not moved the cursor when the next onKeyUp event takes place thus loosing some characters.
This is the code that changes the position:
function SetCursorToTextEnd(elemId) {
var elem = document.getElementById(elemId);
alert(window.event.which);
if (elem != null) {
if (elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', elem.value.length);
range.select();
}
else {
if (elem.selectionStart) {
elem.focus();
elem.setSelectionRange(elem.value.length, elem.value.length);
}
else
elem.focus();
}
}
}
What would be the best way to implement a simple auto complete behavior for each keystroke in a textbox?
Hope you can help. JavaScript isn't my strong side ;)
--
Christian