Inserting text into a radtextbox through javascript!

4 posts, 0 answers
  1. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 22 Aug 2008 Link to this post

    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
  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 25 Aug 2008 Link to this post

    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.
  3. Vithiya
    Vithiya avatar
    41 posts
    Member since:
    May 2008

    Posted 25 Aug 2008 Link to this post

    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
  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 26 Aug 2008 Link to this post

    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.
Back to Top