Jump to content

Textarea With Javascript


phpcodec

Recommended Posts

<script language="JScript">
function txtScroll()
{
txtTest.scrollTop = txtTest.scrollTop+1;
setTimeout('txtScroll()', 100)
}
</script>
<textarea id="txtTest" rows=5>TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text 
TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text 
TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text </textarea>

Mess with the 100 number for speed.

There's a small problem with that code in that once it starts - it never stops - even when the text area has reached the bottom of the text. That means it is continually running on the client's machine.

 

I would suggest using scrollheight as a trigger for when the script can be exited (you can always restart the script if the user moved the slider). Of course scroll height will always be greater than scroll top because of the top and bottom scroll buttons, but this will at least exit the script shortly after it reaches the bottom:

 

<html>
<head>

<script language="JScript">
function txtScroll(textareaID)
{
    textareaObj = document.getElementById(textareaID);
    textareaObj.scrollTop = textareaObj.scrollTop+1;

    if (textareaObj.scrollTop < textareaObj.scrollHeight) {
        setTimeout('txtScroll(\''+textareaID+'\')', 10);
    }
}
</script>
</head>

<body>
<textarea id="txtTest" rows=5 onclick="txtScroll(this.id)">TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text 
TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text 
TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text TEST Text </textarea>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.