I just wrote something that allows you to progamatically select text inside an element(textarea/textbox etc.).
Maybe this can help :
function setSelection(elem,start,end){
elem = document.getElementById(elem);
if(elem){
switch(arguments.length){
case 1:
elem.select();
break;
case 2:
end = elem.value.length;
case 3:
if( elem.setSelectionRange ){
elem.setSelectionRange(start,end);
}
else{ //IE branch
var range = elem.createTextRange();
range.moveStart("character",start);
//IE measures moveEnd from end of string.
// our function takes end coord from the start of the content itself.
// for example, string of length 10 and you want to select to end at 8th character.
// so you would give end=8 which is == -10 + 8 = -2
range.moveEnd("character", -elem.value.length + end);
range.select();
}
}
}
};