This is a migrated thread and some comments may be shown as answers.

Set Focus to the end of text.

7 Answers 370 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Rahul Khinvasara
Top achievements
Rank 1
Rahul Khinvasara asked on 30 Jun 2009, 11:25 AM
hi

i am using Q1 2007 version. when i type in a editor and click on button i want to set cursor position to the end of text

Right now problem is  when i click on button, page is  post back, so focus is getting lost.

please give me the solution ASAP.

regards

rahul.


7 Answers, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 03 Jul 2009, 08:04 AM
Hello Rahul,

To prevent your button from posting the whole page back, you will need to add a return false;, e.g.

<input type="button" onclick="focusEditor();return false;">

One of the easiest ways to move the cursor to the end of the editor content is to select all content and then collapse the selection to the end, e.g.

function focusEditor()
{
  var editor = $find("<%=RadEditor1.ClientID%>");
  var doc = editor.get_document(); //or get_Document() in earlier versions such as Q1 2007
  doc.execCommand("SelectAll", null, false);
  //Collapse selection to the end
  editor.getSelection().collapse();
}

Greetings,
Tervel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rahul Khinvasara
Top achievements
Rank 1
answered on 04 Jul 2009, 06:23 AM
hi

i tried your code. when i click on button,Editor data will save and after saving data, i want to set focus to the end of text.
if I don't post back the page , it set the focus to the end of Text. but i don't want that.
please give me the suggestion.

rahul

0
Rumen
Telerik team
answered on 08 Jul 2009, 02:47 PM
Hello Rahul,

Here is an example that will set the cursor to the end of the text after a postback:

<telerik:radeditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1"
    <Content>sample content for test 123</Content> 
</telerik:radeditor> 
<asp:Button ID="Button1" runat="server" Text="Submit" /> 
<script type="text/javascript"
function OnClientLoad(editor, args) 
  setTimeout(function() 
  { 
      editor.setFocus(); 
      var doc = editor.get_document(); //or get_Document() in earlier versions such as Q1 2007 
      doc.execCommand("SelectAll"nullfalse); 
      //Collapse selection to the end 
      editor.getSelection().collapse(); 
  }, 100); 
</script> 



All the best,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rahul Khinvasara
Top achievements
Rank 1
answered on 09 Jul 2009, 01:14 PM
hi

 I tried your code. but still i am getting an java script error.

"Object doesn't  support this property or method".  Following  line has error:

  var doc = editor.get_document();

  I think he is not supporting these methods for rad Editor ( Q1 2007  version ). i have used both methods get_documents(); and        
   get_Documents();

Please give me the solution ASAP.

Regards

rahul
0
Tervel
Telerik team
answered on 14 Jul 2009, 07:12 AM
Hello Rahul,

No method (or variation thereof) called get_documents exists in RadEditor (nor has it ever existed).
If you are using an outdated version of the editor such as Q1 2007, then the method to call would be
get_Document, but not get_Documents.


Sincerely yours,
Tervel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nick
Top achievements
Rank 1
answered on 17 Sep 2012, 08:45 AM
Hi Rumen!

I am able to set focus to the editor content area and cursor in the end... 

But when the content is too large , the cursor is still in the end but I am unable to scroll to the cursor ( i.e the end of the content )

Please help me in this..

Thanks..

0
Rumen
Telerik team
answered on 17 Sep 2012, 08:49 AM
Hi,

In such case you can fire the editor.get_contentAreaElement().scrollIntoView(); method.

Kind regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
Rahul Khinvasara
Top achievements
Rank 1
Answers by
Tervel
Telerik team
Rahul Khinvasara
Top achievements
Rank 1
Rumen
Telerik team
Nick
Top achievements
Rank 1
Share this question
or