Set Focus to the end of text.

8 posts, 0 answers
  1. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 30 Jun 2009 Link to this post

    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.


  2. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 03 Jul 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 04 Jul 2009 Link to this post

    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

  5. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 08 Jul 2009 Link to this post

    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.
  6. Rahul Khinvasara
    Rahul Khinvasara avatar
    303 posts
    Member since:
    Aug 2007

    Posted 09 Jul 2009 Link to this post

    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
  7. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 14 Jul 2009 Link to this post

    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.
  8. Nick
    Nick avatar
    23 posts
    Member since:
    Jan 2012

    Posted 17 Sep 2012 Link to this post

    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..

  9. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 17 Sep 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017