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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.