473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

scroll textbox to bottom? (IE)

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(elemid)
{
elem = document.getElementById(elemid);
if(elem)
{
elem.focus();
MoveToEnd(elem);
elem.focus();
}
}

function MoveToEnd(Element)
{
if ( Element.createTextRange )
Element.createTextRange().text += "";
else if ( Element.insertionPoint )
Element.insertionPoint = Element.text.length;
}

</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(document.Form1.Textbox1);
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.MoveToEnd(elem);
document.Form1.Textbox1.elem.focus();
document.Form1.Textbox2.focus();

//ATTEMPT #4
document.Form1.Textbox1.focus();
document.Form1.Textbox1.MoveToEnd(elem);
document.Form1.Textbox1.elem.focus();
document.Form1.Textbox1.doScroll();
document.Form1.Textbox2.focus();

//ATTEMPT #5
MoveToEnd(document.Form1.Textbox1);
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(document.Form1.Textbox1);
document.Form1.Textbox1.doScroll('down');
document.Form1.Textbox2.focus();

//ATTEMPT #7
document.Form1.Textbox1.doScroll('down');
document.Form1.Textbox2.focus()

Jul 23 '05 #1
4 7193
Mad Scientist Jr wrote:
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).


Isn't this what HTML anchors are for?

Add an anchor at the appropriate place, then modify the
document.location. The browser will then work out how much to scroll
and it is likely far more cross-browser than a "scroll by" method.
--
Zif
Jul 23 '05 #2
thanks for your reply...
what I am trying to accomplish is to scroll to the bottom of a text
area in a form (inside the textarea), not the bottom of the html page
itself.

Jul 23 '05 #3
Mad Scientist Jr wrote:
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(elemid)
{
elem = document.getElementById(elemid);
if(elem)
{
elem.focus();
MoveToEnd(elem);
elem.focus();
}
}

function MoveToEnd(Element)
{
if ( Element.createTextRange )
Element.createTextRange().text += "";
else if ( Element.insertionPoint )
Element.insertionPoint = Element.text.length;
}

</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(document.Form1.Textbox1);
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.MoveToEnd(elem);
document.Form1.Textbox1.elem.focus();
document.Form1.Textbox2.focus();

//ATTEMPT #4
document.Form1.Textbox1.focus();
document.Form1.Textbox1.MoveToEnd(elem);
document.Form1.Textbox1.elem.focus();
document.Form1.Textbox1.doScroll();
document.Form1.Textbox2.focus();

//ATTEMPT #5
MoveToEnd(document.Form1.Textbox1);
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(document.Form1.Textbox1);
document.Form1.Textbox1.doScroll('down');
document.Form1.Textbox2.focus();

//ATTEMPT #7
document.Form1.Textbox1.doScroll('down');
document.Form1.Textbox2.focus()


Mad:

window.onload = function()
{
setTimeout(
'document.getElementById("Textbox1").scrollTop=100 00'
,50
);
document.getElementById("Textbox2").focus();
}

You may be confusing older style (DOM 0) hierarchial object references,
which use form/element names (document.form_name.field_name) with DOM
1+ document.getElementById, which uses the element's (string) id
assigned via HTML. Be sure and id the fields as well for the above to
work. The timer delay is just an expedient necessary in some browsers
to allow the field to 'set up' before scripting it. Element.scrollTop
is well-supported by now; the high value assures (more or less) that
the entire element will be scrolled.

Jul 23 '05 #4
I got it working great - just count the # of carriage returns on the
asp.net codebehind (carriage returns = mystring.len - replace(mystring,
vbcrlf) / 2) and divide it by the # of rows in the textbox to get
"pages", and send that number as a parameter X to a javascript function
with a doScroll(pagedown), which page downs X times, That way it is
guaranteed to be the correct # of pages, and pagedown is FAST (doing
scroll down by # of lines is slow, you can literally see the textarea
scroll!). Anyway it works great !

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Simon Wigzell | last post by:
I want to display HTML text inside a div and have the page open scrolled to the bottom. (My div has overflow:auto so that it appears with scroll bars) I have found this that works on a textarea:...
0
by: Alex Moskalyuk | last post by:
I am using System.Windows.Forms.TextBox to publish some real-time data that's coming off the external devices. My data is fed into the TextBox with proper precautions not to exceed the MaxSize...
7
by: Mel Weaver | last post by:
Hello, How do you scroll to the bottom of a multiline textbox in code? Mel
1
by: JC | last post by:
I'm sure you've all seen the save scroll position from 4 guys from rolla which can be found here > http://aspnet.4guysfromrolla.com/articles/111704-1.aspx BUT try to get that to work AND still be...
3
by: Rob T | last post by:
I have a multiline textbox that shows a log. When I keep adding items to the textbox, I would like it to autoscroll to the bottom. I thought moving the cursor to the end would do it like (ie....
0
by: Rachel | last post by:
I am developing an application for Windows Mobile devices using C#. I have a form that has several controls (labels and textboxes that are dynamically created on opening the form) and a vertical...
0
by: Brian Keating | last post by:
Hi there, Does anyone know if i can determin if the scroll position is at the bottom of my textbox? I can get the scroll position fine, but how do i know if it's actually at the bottom? ...
6
Coldfire
by: Coldfire | last post by:
Hello I am doing a ASP.Net website project where i am having a problem of textbox its attributes are <asp:TextBox ID="Description" TextMode=SingleLine CssClass="serviceBox" Width="250"...
1
by: NehaDas | last post by:
Hello Everyone ! Iam relatively new to .NET C# and m still in the process of exploring various options. Any help with regard to this query will be highly appreciated ... Iam working on an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.