Click here to Skip to main content
12,360,334 members (54,930 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
How to get the value of ASP.NET TextBox using the JavaScript code
Posted 26-Jul-11 5:51am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

was this [^]so difficult?

Say you have a textbox like follows:

<asp:TextBox id="txtMyTextBox" runat="Server" Text="1234"></asp:TextBox>

In javascript do the following to get value:

var value = document.getElementById('<%=txtMyTextBox.ClientID%>').value;
  Permalink  
Comments
Uday P.Singh 26-Jul-11 11:56am
   
correct my 5!
Manas Bhardwaj 26-Jul-11 11:59am
   
thanks!
AshishChaudha 18-Dec-12 2:03am
   
Perfect!! my +5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try as below.

<script type="text/javascript">
 
function Test()
{
    var textboxValue = document.getElementById('<%= Textbox1.ClientID %>').value;
}
 
</script>
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

hey! try
<script type="text/javascript">
    function GetTextBoxValue() {
        var value = document.getElementById('<%=TextBox1.ClientID%>').value;
        alert(value);
        return false;
    }
</script>

Reference Link :- Get TextBox value using JavaScript[^]
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

<script type="text/javascript">
 
function getTextBoxValue()
{
    var txtValue = document.getElementById(<%= Textbox1.ClientID %>;).value;
    alert(txtValue);
}
 
</script>
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

Hi

Lets say you have a asp.net textbox like below

<asp:textbox id="txtName" runat="server" xmlns:asp="#unknown" />

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

var name = document.getElementById("<%=txtName.ClientID %>").value;

for more details please refer: get asp.net textbox value using javascript
  Permalink  
Comments
VICK 31-Oct-13 6:26am
   
Have you seen the post date ?? it is of Jul 2011. So does not seems logical to answer an already solved and Old question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 31 Oct 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100