Hi
Is there any way to set the cursor position from javascript? ie, when a button is clicked move the cursor from position 10 to position 20?
I've tried using the standard text input selection range, however without success.
Thanks
David
Is there any way to set the cursor position from javascript? ie, when a button is clicked move the cursor from position 10 to position 20?
I've tried using the standard text input selection range, however without success.
Thanks
David
6 Answers, 1 is accepted
0
Hi David,
We have answered your other support ticket. For convenience I pasted the answer bellow:
The requested feature is not supported out-of-the box by RadEditor and it does not offer client-side API for it.
That is why you should implement your scenario using the underlying API of the browser. You need to get a reference to the RadEditor Document with editor.get_document(); and create a range.
//get a reference to the document object in the editor content area
editor.get_document();
//You can create a range in IE like this:
editor.get_document().selection.createRange();
After that you will be able to use the following methods
duplicate(), move(), moveStart(), moveEnd() and select()
which will allow you to control the selection in the content area.
Best regards,
George
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
We have answered your other support ticket. For convenience I pasted the answer bellow:
The requested feature is not supported out-of-the box by RadEditor and it does not offer client-side API for it.
That is why you should implement your scenario using the underlying API of the browser. You need to get a reference to the RadEditor Document with editor.get_document(); and create a range.
//get a reference to the document object in the editor content area
editor.get_document();
//You can create a range in IE like this:
editor.get_document().selection.createRange();
After that you will be able to use the following methods
duplicate(), move(), moveStart(), moveEnd() and select()
which will allow you to control the selection in the content area.
Best regards,
George
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
David
Top achievements
Rank 1
answered on 09 Apr 2008, 08:15 AM
Hi
Apologies this isn't working for me. I posted a new thread as the question is slightly different.
What I want to do is handle the key down button press, then before the character is input into the text move the cursor say ten positions along. So for example:
I have the following text with the cursor position where I have a pipe:
12|34567890123456789
If I press the A key I want the character to be placed as below:
123456789012A3456789
I've tried using moving the range as previously suggested however am having no luck.
Thanks
David
Apologies this isn't working for me. I posted a new thread as the question is slightly different.
What I want to do is handle the key down button press, then before the character is input into the text move the cursor say ten positions along. So for example:
I have the following text with the cursor position where I have a pipe:
12|34567890123456789
If I press the A key I want the character to be placed as below:
123456789012A3456789
I've tried using moving the range as previously suggested however am having no luck.
Thanks
David
0
Hi David,
Here is an example how to implement your scenario:
Once again, please note that this feature is not supported by RadEditor out-of-the box and the implementation is up to the developer using the control.
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Here is an example how to implement your scenario:
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| <script type="text/javascript"> |
| function OnClientLoad(editor, args) |
| { |
| editor.attachEventHandler("onkeydown", function(e) |
| { |
| if (e.keyCode == "65") // If A key is pressed |
| { |
| var range = editor.get_document().selection.createRange(); |
| var oRange = range.duplicate(); |
| oRange.moveStart("character", 5); |
| oRange.select(); |
| } |
| }); |
| } |
| </script> |
| <telerik:radeditor runat="server" ID="RadEditor1" |
| OnClientLoad="OnClientLoad"> |
| <Content> |
| 1234567890123456789 |
| </Content> |
| </telerik:radeditor> |
Once again, please note that this feature is not supported by RadEditor out-of-the box and the implementation is up to the developer using the control.
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
David
Top achievements
Rank 1
answered on 09 Apr 2008, 04:50 PM
Excellent, that's what I was after. (I wasn't calling .select() - new to this).
Thanks for you help!
Thanks for you help!
0
David
Top achievements
Rank 1
answered on 09 Apr 2008, 05:33 PM
Okay sorry.... is there a way to do this in firefox?
0
Hi David,
The selection and the TextRange objects have very little in common in IE and FireFox.
In Mozilla you will need to look at getRangeAt(0):
http://developer.mozilla.org/en/docs/DOM:Selection
http://www.mozilla.org/docs/dom/domref/dom_range_ref.html
Please, note that it is up to you to implement the solution. If you succeed with the implementation, you can share the code with our community.
Kind regards,
Rumen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The selection and the TextRange objects have very little in common in IE and FireFox.
In Mozilla you will need to look at getRangeAt(0):
http://developer.mozilla.org/en/docs/DOM:Selection
http://www.mozilla.org/docs/dom/domref/dom_range_ref.html
Please, note that it is up to you to implement the solution. If you succeed with the implementation, you can share the code with our community.
Kind regards,
Rumen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
