Page 1 of 1

javascript scroll to page area [SOLVED]

Posted: Sun Sep 16, 2007 8:51 pm
by s.dot
I have a page loading that I give focus to a textarea. Sometimes the textarea isn't always above the "fold" of the page, in which case I want the page to scroll down a little bit to show the textarea.

Code: Select all

document.getElementById('txtForm').scrollIntoView(true);
document.getElementByTagName('body').scrollBy(0, 500000);
Both of those obviously don't work. How would I go about doing this?

Posted: Sun Sep 16, 2007 9:34 pm
by feyd
document.getElementById('blah').focus()?

Posted: Sun Sep 16, 2007 9:37 pm
by s.dot
feyd wrote:document.getElementById('blah').focus()?
That is putting the cursor in the textarea but doesn't scroll the page down?

Posted: Sun Sep 16, 2007 9:42 pm
by feyd
Maybe if you target its container or another element scrollIntoView would work... although it appears it should work on textarea elements.

Posted: Mon Sep 17, 2007 12:35 am
by s.dot
It would help if I was uploading the correct document after saving changes. :roll:

EDIT| Just so you guys know, it's posts like these that make me feel like a moron.
/thinks about abusing mod status and deleting topic
:P