473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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( )

Jul 23 '05 #1
4 7227
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.locati on. 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(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( )


Mad:

window.onload = function()
{
setTimeout(
'document.getEl ementById("Text box1").scrollTo p=10000'
,50
);
document.getEle mentById("Textb ox2").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.getEle mentById, 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.scrollT op
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(mystrin g,
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(pagedo wn), 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
12554
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: document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight; But this doesn't work on a div. I am using a div because the text I am displaying contains HTML. Surely it is possible to simply set a scroll bar to the bottom in a div???...
0
2655
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 limit. I use the AppendText() method of the TextBox class and tried playing with ScrollToCaret(), but that didn't seem to do anything different than normal behavior. I am getting the TextBox that supports auto-scrolling on some machines (i.e. the...
7
69356
by: Mel Weaver | last post by:
Hello, How do you scroll to the bottom of a multiline textbox in code? Mel
1
8685
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 able to set the focus to a control. Here's the problem, when you set the focus by using the registerstartupscript method the control gets the focus after the scroll position has been set. When this happens the scroll position
3
11974
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. boxHistory.SelectionStart=999999), which does move the cursor, but doesn't scroll. How would I do this? Thanks. -Rob T.
0
2306
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 scroll bar. The number of controls varies. Everything works well and the scroll bar resizes acc to the number of controls. Only problem I am having is that when the user is entering data and the control is at the bottom of the form the scroll bar...
0
2078
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? thanks in advance Brian.
6
6525
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" Height="45" Runat="server" MaxLength="1000" /></asp:TextBox> and the CssClass .serviceBox
1
2906
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 application that somewhat is similar to outlook . It will have a list of messages received on top and a reading pane below displaying the message selected by user. The problem is as follows : The screen is structured in the form of 3 taskcards : 1)New...
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.