Net-informations.com
SiteMap  | About    

Textbox value in Javascript

The following Asp.Net program shows how to get asp.Net TextBox value by using JavaScript.

Asp.Net Code

document.getElementById('<%= txt_id.ClientID %>').value;

The value property sets or returns the value of the value attribute of a text field. It contains the default value OR the value a user types in.

Full Source:

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <script type="text/javascript"> function getValue() { var getVal = document.getElementById('<%= txt_id.ClientID %>').value; alert(getVal); } </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="txt_id" runat="server" ></asp:TextBox> <br /> <br /> <input type="button" value="Get in Js" onclick="getValue()" /> <br /> </form> </body> </html>

Setting Asp.Net Textbox value using Javascript

Inorder To set the value of textbox, we need to use:

document.getElementById(“txt_id”).value = inputValue;

Getting Asp.Net Label value using Javascript

Lets say you have a asp.net label like below

<asp:Label ID="lbl_id" runat="server" Text="Test Label"/>

then you can get the value of the above label using javascript using the below code

var getVal = document.getElementById("<%=lbl_id.ClientID %>").innerHTML;






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.