Search code examples
javascriptasp.nethtmltextboxajaxcontroltoolkit

Get the Value of an ASP TextBox Element with an HTMLEditorExtendor Attached, Using JavaScript


I am having an odd issue. I have a textbox with an ajaxToolkit HtmlEditorExtender attached to it. I need to get the text that is put in this textbox using javascript.

I have a simple test set up:

var element = document.getElementById('<%=txtUserInput.ClientID%>');
alert(element);

This seems to report that the object is an HTML textarea element so I use .value to try and get what is inside then I tried .text because .value did not work.

alert(element.Value);
alert(element.Text);

These both give me a popup with "undefined" in it. How do I get the value out of this textbox?

I have seen this post:

JavaScript getElementById for ASP.NET Control returns null?

and this one too:

JavaScript get TextArea input via .value or .innerHTML?

Here is my HTML Element

<asp:TextBox ID="txtUserInput" Height="100%" Rows="10" Width="100%" TextMode="MultiLine"
runat="server" />
        <ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender_txtUserInput"
            TargetControlID="txtUserInput" DisplaySourceTab="false" runat="server">
            <Toolbar>
                <ajaxToolkit:Bold />
                <ajaxToolkit:ForeColorSelector />
                <ajaxToolkit:Italic />
                <ajaxToolkit:JustifyLeft />
                <ajaxToolkit:JustifyCenter />
                <ajaxToolkit:JustifyRight />
            </Toolbar>
        </ajaxToolkit:HtmlEditorExtender>

Solution

  • ".Value" and ".Text" are ASP.NET control properties, not Javascript element properties. You need to use ".value".