I have a textbox that i am adding to (in codebehind of ASP.NET) and
need to ensure that the focus is scrolled to the bottom of the textbox
each time the page refreshes, and then set focus to a 2nd textbox
(which the user types input into).
I have tried a couple functions I found posted online but they don't
work (see below)
The closest I got was using the scrolldown method:
http://msdn.microsoft.com/library/default.asp?
url=/workshop/author/dhtml/reference/methods/doscroll.asp
but this only scrolls down at most 1 page. How do I scroll to the
absolute bottom no matter how much text is in the box?
Thanks
in Head:
<script type="text/javascript">
function focusById(elemi d)
{
elem = document.getEle mentById(elemid );
if(elem)
{
elem.focus();
MoveToEnd(elem) ;
elem.focus();
}
}
function MoveToEnd(Eleme nt)
{
if ( Element.createT extRange )
Element.createT extRange().text += "";
else if ( Element.inserti onPoint )
Element.inserti onPoint = Element.text.le ngth;
}
</script>
</HEAD>
In onload (various versions, #6 sort of worked):
// SCROLL TO BOTTOM OF TEXTBOX #1 AND SET FOCUS ON TEXTBOX #2
//ATTEMPT #1
focusById(docum ent.Form1.Textb ox1);
document.Form1. Textbox2.focus( );
//ATTEMPT #2
var sText=document. Form1.Textbox1. value;
document.Form1. Textbox1.value= sText;
document.Form1. Textbox2.focus( );
//ATTEMPT #3
document.Form1. Textbox1.focus( );
document.Form1. Textbox1.MoveTo End(elem);
document.Form1. Textbox1.elem.f ocus();
document.Form1. Textbox2.focus( );
//ATTEMPT #4
document.Form1. Textbox1.focus( );
document.Form1. Textbox1.MoveTo End(elem);
document.Form1. Textbox1.elem.f ocus();
document.Form1. Textbox1.doScro ll();
document.Form1. Textbox2.focus( );
//ATTEMPT #5
MoveToEnd(docum ent.Form1.Textb ox1);
document.Form1. Textbox2.focus( );
//ATTEMPT #6
//seemed to work but only scrolls down a little
//how do i scroll to the absolute end
//no matter how much text is in Textbox1 ?
MoveToEnd(docum ent.Form1.Textb ox1);
document.Form1. Textbox1.doScro ll('down');
document.Form1. Textbox2.focus( );
//ATTEMPT #7
document.Form1. Textbox1.doScro ll('down');
document.Form1. Textbox2.focus( )