DefaultValue Empty for MultiLine Textbox

7 posts, 1 answers
  1. Ryan
    Ryan avatar
    61 posts
    Member since:
    Jul 2009

    Posted 21 Jul 2011 Link to this post

    Hello -

    I'm trying to access a RadTextBox's defaultValue through JavaScript.  When I have the textbox's mode set to SingleLine, I can get the defaultValue through the following JavaScript:

    this.defaultValue;

    However, when I have the textbox's mode set to MultiLine, the defaultValue comes up as an empty string.  Does anybody have any thoughts on how to get the defaultValue of a multiline textbox?
  2. Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 26 Jul 2011 Link to this post

    Hello Ryan,

    Try to use value attribute instead of defaultValue to get the text inside the input.

    var value = textBox.get_value() ; //where textBox is the client object of type RadTextBox
     
    var value = textBoxDomElement.value; // where textBoxDomElement is the input DOM element

    Greetings,
    Vasil
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. Ryan
    Ryan avatar
    61 posts
    Member since:
    Jul 2009

    Posted 27 Jul 2011 Link to this post

    Thanks for your response.  I'm afraid I wasn't clear, then.  I'm not looking for the current value of the textbox, but the value the textbox had when it was first created on the page.  This is accomplished in normal textboxes through the defaultValue property in JavaScript.  However, the defaultValue property of this multi-line textbox does not return anything.

    Please advise.
  4. Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 27 Jul 2011 Link to this post

    Hi Ryan,

    Excuse me that I didn't explain in more details why you can't use "defaultValue" property.

    When the RadTextBox is single line it is rendered like an "Input".
    And when it is multi line it is rendered like textarea.

    Since the "textarea" is not a "TextObject" (input with type="text"), the rendered element by the RadTextBox will not have "defaultValue" property.

    Best wishes,
    Vasil
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  5. Ryan
    Ryan avatar
    61 posts
    Member since:
    Jul 2009

    Posted 27 Jul 2011 Link to this post

    Thanks again for the reply.  Both <input> and <textarea> have defaultValue properties in JavaScript.  The following Javascript/HTML successfully returns the default value of both the input and textarea:

    HTML:
    <input type="text" id="tbxTestInput" name="tbxTestInput" value="Initial Value - Input" />
    <textarea rows="3" cols="30" id="tbxTestTextArea" name="tbxTestTextArea">Initial Value - TextArea</textarea>

    JavaScript:
    <script language="javascript" type="text/javascript">
    try {
            alert(document.getElementById('tbxTestInput').defaultValue);
            alert(document.getElementById('tbxTestTextArea').defaultValue);
    }
    catch(err) {
            alert(err.description);
    }
    </script>

    Do you have any other thoughts on the matter?  Thanks.

  6. Answer
    Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 28 Jul 2011 Link to this post

    Hi Ryan,

    Excuse me for my mistake. The textarea indeed has defaultValue. Please see the example below that shows how to get it for the MultiLine RadTextBox.

    <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="some text">
    </telerik:RadTextBox>
    <telerik:RadTextBox ID="RadTextBox2" runat="server" TextMode="MultiLine" Text="Some text inside the multi line textbox">
    </telerik:RadTextBox>
    <asp:Button runat="server" OnClientClick="showDefaults();return false;" />
    <script type="text/javascript">
     
      function showDefaults()
      {
        alert($find("RadTextBox1").get_element().defaultValue);
        alert($find("RadTextBox2").get_element().defaultValue);       
      }
    </script>

    Greetings,
    Vasil
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  7. Ryan
    Ryan avatar
    61 posts
    Member since:
    Jul 2009

    Posted 28 Jul 2011 Link to this post

    Thanks for passing on the example using get_element() - I wasn't aware I needed to use that.  I've accomplished what I need by setting the RadTextBox's .ClientEvents.OnBlur = "FunctionName".  On the JavaScript side, the following code works:

    function FunctionName(thisSender) {
        alert(thisSender.get_element().value); // Current Value
        alert(thisSender.get_element().defaultValue); // Default Value
        alert(thisSender.get_element().name); // Name
    }

    Thanks again.  All is well.
Back to Top