Possible to trap the cursor position w/ OnBlur event and get_caretPosition()?

4 posts, 1 answers
  1. Scott Smith
    Scott Smith avatar
    14 posts
    Member since:
    Mar 2010

    Posted 19 Apr 2010 Link to this post

    I'm trying to get the last position of the cursor when the user clicks outside of the RadTextbox, but I'm not quite sure it's working how I was hoping. I added an OnBlur client event in the mark-up:

    <telerik:RadTextBox ID="rtxtTemplateContent" Runat="server" Height="100px" TextMode="MultiLine" Width="250px">  
        <ClientEvents OnBlur="setCursorPosition" /> 

    Next I have my JavaScript:

    function setCursorPosition(sender) {  
        var cursorPosition = sender.get_caretPosition()  
        document.getElementById("hdnCursorPosition").value = cursorPosition;  

    My goal is to trap the last cursor position and save it in a hidden field on the page for use w/ drag'n'drop functionality from a RadListBox to the RadTextBox. It seems like it's working correctly except the numbers come out really random. For instance, I put 10 characters in the textbox and then put the cursor in the middle and clicked out of the textbox, but the number returned by get_caretPosition() was 80? Doesn't make sense to me... any ideas or suggestions? Is what I'm doing possible or has the cursor position been lost by the time the OnBlur event is fired?
  2. Answer
    Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 22 Apr 2010 Link to this post

    Hello Scott,

    Note that when the OnBlurEvent fires the caret is already out of the TextBox and you will not be able to get the position correctly. The best option for your scenario is to use the OnMouseOut client event and get the cursor position.

    Maria Ilieva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Subash
    Subash avatar
    1 posts
    Member since:
    Nov 2011

    Posted 01 Nov 2011 Link to this post


    I am facing problem with get_carePosition() method. As per our need, we have to retain the last cursor position even the user move out of the screen and come back. We face the problem in RADMaskedTextBox, RADDateInput and RADNumericTextBox, We dont want the selectAll effect. I used get_carePosition() on onblur to save the position in hidden field and onfocus event i set the caret position using set_carePosition(). This works for me in most of the scenario, But not works in one scenario. Scenario is : for example, i have SSN field of 9 digit as xxx-xx-xxxx format. I enter 1 and 2. Then delete 2 and 1. Now i expect that get_carePosition() has to return 0. But it returns 1, I am not sure why it like this,I thing the minimum return value for get_carePosition()  is one or zero?.I could not get any other event to trap than Onblur for my need. Mouse or Key events did not help me at all. Need your solution here please.
  4. Darwin
    Darwin avatar
    9 posts
    Member since:
    Jan 2013

    Posted 21 Jan 2013 Link to this post

    That works for people who use the mouse to navigate the form but it doesn't work if somebody tabs out of the textbox to the next control.  Is there not a better way?
Back to Top