Hi all,

Here's an interface I'm working with for my application

create link

The interface allows for a user to select a portion of text in the textarea and then add a url link to it.

So the user does the following:

- Selects the text in the textarea
- Then goes into the dialog area above and adds a url or selects another option
- then the user will click on the "create" button to create the link

When this happens the focus within the textarea goes right back up to the top of the textarea. However I have a good amount of text that scrolls down into the textarea. I want to have the focus in the textarea to remain focused where I just inserted the url.

Could something like onfocus get the focus back to where the url was inserted? Basically I need the focus to remain at the caret position where the url was inserted. However in a textearea box where the user has scrolled down, the focus goes back up to the top of the box, but the caret position is still active down below. I need it so that the focus always stays with the active caret position.

here's the javascript function I use:

//  this works in Mozilla!! ahh!
function insert_url() {
// url that will be used in link
var url;
var xml_name = document.editform.xml_name.value;
// from drop down menu
var url_insert = document.editform.url_insert.value;
var url_text = document.editform.url.value;
var is_xml = document.editform.is_xml.checked;
//alert ( " value of is_xml " + is_xml );
//alert( "values -->" + "  " + url )

if( url_insert !='') {
    url = url_insert;
    url = url_text;
var txt = document.getElementsByTagName('textarea')[0];
var selectedText = txt.value.substr(txt.selectionStart, (txt.selectionEnd - txt.selectionStart));
var s2 = txt.value;
if( is_xml == true ) {
// track-> true must be enabled!
  var link_start= '<SimpleURLProperty name="' + xml_name + '" track="true" type="plain" href="' + url + '" label="' + selectedText + '"><a href="' + url + '">';
  var link_end = '</a></SimpleURLProperty>';
  var link_start= '<a href="' + url + '">';
  var link_end = '</a>';

txt.value = s2.substring(0, txt.selectionStart)
+ link_start + selectedText + link_end +  s2.substr(txt.selectionEnd + 1);

// trying to get focus back to where the user selected text in the beginning
// right now it puts focus back at the top of the textarea
// document.getElementsByTagName('textarea')[0].onfocus();

return true;