How to scroll a TextArea

  • Thread starter Stefano Incontri
  • Start date
S

Stefano Incontri

Hi All,

how can I scroll a TextArea to its last position at the bottom?

Thanks,
Stefano
 
B

Bagbourne

Stefano Incontri said:
Hi All,

how can I scroll a TextArea to its last position at the bottom?

element.scrollTop = element.scrollHeight - element.clientHeight;
 
Y

Yep

Stefano Incontri said:
how can I scroll a TextArea to its last position at the bottom?

In IE, collapsing a TEXTAREA range to the end and selecting it should
result into a scrolldown; as for other browsers I don't think it's
currently doable.


<textarea id="ta" rows="5" cols="30">
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
</textarea>

<input type="button" value="scroll" onclick="f('ta')" />

<script type="text/javascript">
function f(ta_id){
var d=document, ta, rng;
if(d.all){
ta=d.all[ta_id];
if(ta && ta.createTextRange){
rng=ta.createTextRange();
rng.collapse(false);
rng.select();
}
}
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top