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

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

3 Answers 863 Views
Input
This is a migrated thread and some comments may be shown as answers.
Scott Smith
Top achievements
Rank 1
Scott Smith asked on 19 Apr 2010, 06:03 PM
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" /> 
</telerik:RadTextBox> 

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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Maria Ilieva
Telerik team
answered on 22 Apr 2010, 02:18 PM
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.


Regards,
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.
0
Subash
Top achievements
Rank 1
answered on 01 Nov 2011, 11:40 AM
Hello,

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.
0
Darwin
Top achievements
Rank 1
answered on 21 Jan 2013, 07:50 PM
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?
Tags
Input
Asked by
Scott Smith
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Subash
Top achievements
Rank 1
Darwin
Top achievements
Rank 1
Share this question
or