JavaScript and client side scripting.
Moderator: General Moderators
lovelf
Forum Contributor
Posts: 153 Joined: Wed Nov 05, 2008 12:06 am
Post
by lovelf » Tue Mar 17, 2009 2:23 am
Is it possible to set focus on an element without moving the scrollbar if this element is below available height ?
Code: Select all
<textarea id="rfz" style="position:absolute;bottom:-100px;"></textarea>
Code: Select all
<script type="text/javascript">
function rfz(){document.getElementById("rfz").focus();}
setTimeout(rfz,0);
</script>
volomike
Forum Regular
Posts: 633 Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA
Post
by volomike » Tue Mar 17, 2009 3:46 am
I don't think so. Let's look at this from a different angle. What is it that you are trying to do that would cause you to go down this road in the first place?
lovelf
Forum Contributor
Posts: 153 Joined: Wed Nov 05, 2008 12:06 am
Post
by lovelf » Tue Mar 17, 2009 4:56 am
To use it as an incentive for people to write comments.
The comments textarea is below the articles and I would like to have focus on it but without the scrollbar going down to where the textarea is.
Thanks.
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Tue Mar 17, 2009 5:10 am
How about using an anchor (<a name>) and let people decide wether they want to write a comment or not? An easy way to make the page jump down to the comments field if the article is long.
lovelf
Forum Contributor
Posts: 153 Joined: Wed Nov 05, 2008 12:06 am
Post
by lovelf » Tue Mar 17, 2009 6:37 am
Yes, when the anchor is clicked then the focus is set to the textarea.
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Tue Mar 17, 2009 6:43 am
Sounds nice.