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

狂风中的少年 提交于 2019-12-12 01:26:20

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/12076421/get-the-value-of-an-asp-textbox-element-with-an-htmleditorextendor-attached-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!