How to use javascript to get ASP.NET text field control value

Suppose I have an ASP.NET text box:

<asp:TextBox ID="txtQuantity" runat="server" Text="0"></asp:TextBox>

I want to get the current value of this field in javascript. How can I access this item?

+5
source share
2 answers

use the clientID property

document.getElementByID('<%=txtQuantity.ClientID %>')

More info here

you can also use find

Quoted from the link above:

Additionally, ClientID is used in ASP.NET Ajax as a unique identifier for client-side controls. Therefore, the following JavaScript statement is commonly used:

var control = $ find ("<% = MyControl1.ClientID%>");

+11

txtQuantity.ClientID.

+2

All Articles