Forum Moderators: open

Message Too Old, No Replies

Textarea not scrolling.

cant view the text.

         

appi2

11:52 am on Aug 3, 2007 (gmt 0)

10+ Year Member



Having a little problem with keeping the last line or word in the text area in view.
If you input anything by keyboard the line your typing is always in view. But if you click on the "foo or newline" enough times the textarea scrolls but the text is not in view, so you can't see the last line or text.

Sorry for the poor description of the problem, if you fire the script up in a browser and click foo & newline a few times you understand better :p

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>textarea scroll</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
var keyboard = function () {
var Atags = document.getElementById("foo").getElementsByTagName("li");
for (var t = 0; t < Atags.length; t++) {
Atags[t].onclick = function () {
var theKey = this.innerHTML;
if (this.id == "returnB") theKey = "\n";
document.getElementById("taID").value += theKey;
document.getElementById("taID").focus();
}
}
}
if (window.attachEvent) window.attachEvent("onload", keyboard);
window.onload = keyboard
</script>
</head>

<body>
<textarea id="taID" wrap="off"></textarea>
<ul id="foo">
<li>foo</li>
<li id="returnB">newline</li>
</ul>
</body>
</html>

appi2

2:01 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Solved(ish)
Basic fix would be

document.getElementById("taID").scrollTop = document.getElementById("taID").scrollHeight;
document.getElementById("taID").scrollLeft = document.getElementById("taID").scrollWidth;

Just got to sort out the width of text value and use that to scroll left when it reaches the width of the text area.