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

Inserting text into a radtextbox through javascript!

3 Answers 123 Views
Input
This is a migrated thread and some comments may be shown as answers.
Vithiya
Top achievements
Rank 1
Vithiya asked on 22 Aug 2008, 07:19 PM
Hi,

I have a need to copy text from a field in the child window and paste it into a radtextbox on the parent window. The copy part works fine. It's the pasting that does not happen well. Here is the code that I am using to paste the copied text into the radtextbox field. I see the text being pasted, but the textbox flashes immediately and wipes out my pasted data. Please tell me how I can correct it.

storeCaretPosition = document.selection.createRange();
controlcontext = control;

function insertAtCaret (text)
{      
    var textEl = controlcontext;
    if (textEl != null)
    {
        if (textEl.createTextRange)
            {
             textEl.caretPos =storeCaretPosition.duplicate();
            }
        if (textEl.createTextRange && textEl.caretPos)
            {
             var caretPos = textEl.caretPos;
             caretPos.text =  caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text+' ';
            }
        else
            {
             textEl.value  = text;
            }
        textEl.focus();
    }


Thank you!
vithiya

3 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 25 Aug 2008, 06:12 AM
Hello Vithiya,

You can use the client-side API's set_value() for this purpose. See the complete list of functions available here.

All the best,
Konstantin Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vithiya
Top achievements
Rank 1
answered on 25 Aug 2008, 02:18 PM
Thank you. But set_value() actually replaces the the entire value in the text box. I only want to insert text at the caret position without losing the text that is already there. How can I do that?

Vithiya
0
Konstantin Petkov
Telerik team
answered on 26 Aug 2008, 10:52 AM
Hi Vithiya,

Yes, that is correct. In order to change part of the value only, you should firstly get the current value and create the new result manually with JavaScript. There is no option through the API which could combine the new value based on the caret you need to start replacing the value with.

By the way, with the release of Service Pack 1 of RadControls for ASP.NET AJAX Q2 2008, the RadInput controls expose get/set_caretPosition client-side properties you can use. The release will be uploaded later today.

Greetings,
Konstantin Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Input
Asked by
Vithiya
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Vithiya
Top achievements
Rank 1
Share this question
or