Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with a textbox 1

Status
Not open for further replies.

flexed

Programmer
Joined
Aug 20, 2006
Messages
4
Location
DE
Dear all,

I add some text to the textarea and the text will be added like this:

var mdiv = document.getElementById("messages");

for (i=0; i<2000; i++) {
mdiv.innerHTML = mdiv.innerHTML + "text <br/>\r\n";
}

How can I put the scrollbar down, to the last input? Now, the user have to move the scroll bar, after the text was added. It can be so, that the text will be added dynamically and I want to show the user the actuall block of the information. How can the program follow the input and be down in the box?

Actually I am not going to use textarea, I have created div:

<table><tr><td width="200" height="200"><div id="messages"></div>
</td></tr></table>

<style type="text/css">
#messages {
background: white;
margin-left: 5px;
height: 98%;
padding-left: 5px;
padding-right: 5px;
border: 1px solid #256087;
overflow: scroll;
margin-right: 5px;
}
</style>

It should be like in a chat. But in my case after the text was added, the scroll bar is up and if I move scroll bar, while adding a new portion of information, it's not good.

Thanks in advance.

 
I accidently did this the other day... wasnt what i wanted to do but its what you are after... try putting the below focus cod after the text has been inserted into the textbox.

Code:
mdiv.focus();

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
Thanks. This is exactly I wanted. I have not JavaScript editor, if I had code completen I would solve this problem immediately. Could you advica me some good IDEs for JavaScript?
 
Well i use Dreamweaver MX, but that really isnt the best for finding issues with js, I use a combination of Dreamweaver MX and firebug exstension for firefox works well.


Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]
 
I have tried the focus(). It sets focus correctly, I mean if I go to the other part of a page, the script returns me back. But the scroll bar stays without moving and content dissapear in the text box. The user still have to move scroll bar to see update, but when it updates it jumps.

Well, I suppose, the focus() is not a solution here. Do you have any idea?

Thanks for the answer about IDEs.
 
Yes, the combination of scrollTop and scrollHeight has solved the issue. Great thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top