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

DefaultValue Empty for MultiLine Textbox

6 Answers 288 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 21 Jul 2011, 08:52 PM
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?

6 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 26 Jul 2011, 12:00 PM
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!

0
Ryan
Top achievements
Rank 1
answered on 27 Jul 2011, 02:58 PM
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.
0
Vasil
Telerik team
answered on 27 Jul 2011, 03:56 PM
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.

0
Ryan
Top achievements
Rank 1
answered on 27 Jul 2011, 04:38 PM
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.

0
Accepted
Vasil
Telerik team
answered on 28 Jul 2011, 01:42 PM
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.

0
Ryan
Top achievements
Rank 1
answered on 28 Jul 2011, 09:13 PM
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.
Tags
Input
Asked by
Ryan
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or