Get asp: The value of the text box in the client side using the javascript function does not work

advertisements

This code doesn't display the value, I don't know why?

I have server control:

<asp:TextBox ID="txtTest" runat="server" Visible="false" TextMode="MultiLine"
                    Rows="3" Columns="23" CssClass="white-scroll" />

in javascript function:

var eventText = document.getElementById('<%=txtTest.ClientID%>').value;
alert (eventText);

I enter text then click on button that call the javascript function, but the alert box doesn't display the entered text.

EDIT: when I initialize the text with Text="some text", it is displayed in alert, I want to enter text in client side and get the value of it in the Javascript function.

Thanks


Using label or textbox visible set false so it can access the value in JavaScript

Sol

1)

Make a div and set style="display:none;" so label is not display at UI(browser) but value can access in JavaScript.