I've got an ASP.Net TextBox
that I want to pass it's text value to a JavaScript function. I've tried several different methods, including the one at this answer, Getting Textbox value in Javascript but my value is always returned as undefined
. These textboxes are part of an <asp:UpdatePanel>
but I have tried this outside of the panel, and receive the same error.
This is my current code setup:
ASP.Net
<asp:TextBox ID="txtEmail" runat="server" ClientIDMode="Static"
CssClass="login-boxes" TextMode="Email" MaxLength="255" ValidationGroup="rPage1" />
<asp:TextBox ID="txtTest" runat="server" ClientIDMode="Static"
CssClass="login-boxes" ValidationGroup="rPage1" />
<asp:Button ID="btnAdvance" runat="server" CssClass="login-buttons reg-btn-show"
OnClientClick="testFunction()" UseSubmitBehavior="false" Text="Advance"
OnClick="btnAdvance_Click" ValidationGroup="rPage1" />
JavaScript
var box1 = document.getElementById('<%= txtTest.ClientID %>').value;
var box2 = document.getElementById('<%= txtEmail.ClientID %>');
function testFunction() {
box2.value = box1;
}
What I am trying to achieve, is if I type "Hello" into txtTest
and click btnAdvance
, it should populate txtEmail
with "Hello". How can I achieve this?