restore focus in textarea at the same cursorposition

  • Thread starter Pieter Overbeeke
  • Start date
P

Pieter Overbeeke

Hi all,

I would like to restore focus on in a textarea with the cursor in the
same place it was when it lost focus.
I use getbookmark() on blur and want to use movetobookmark() for
restoring the old-cursorposition.
This is what i have sofar:

===CODE========================================================
<html>
<head>
<script>
bookmark = '';

function do_bookmark(content)
{
bookmark = content.createTextRange().getBookmark();
document.all.bookmarkmemory.value = bookmark;
}

function restore_cursor(content)
{
content.focus();
content.createTextRange().moveToBookmark(bookmark);
}

</script>
</head>
<body>
<form name="aForm">
Bookmark: <br/>
<textarea name="bookmarkmemory" cols="80" rows="5"></textarea><br/>
<b>The textarea:</b> <br/>
<textarea name="aTextArea" onBlur="do_bookmark(this);" cols="80"
rows="10">
This is some sample text. This is some sample text. This is some
sample text. This is some sample text. This is some sample text. This
is some sample text. </textarea>
<br/>
<input type="button" value="restore focus at bookmarked position"
onclick="restore_cursor(this.form.aTextArea);">
</form>
</body>
</html>
===//CODE========================================================

Onblur the bookmark is set (this made visible in the first
textareabox).
By pushing the button i would like to restore the focus in the
textarea at the bookmarked position.

Does anyone have an idea how i can do this?

Thanks and Regards, Pieter Overbeeke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top