Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How to get the value of ASP.NET TextBox using the JavaScript code
Posted

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;
 
Share this answer
 
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!
Try as below.

JavaScript
<script type="text/javascript">

function Test()
{
    var textboxValue = document.getElementById('<%= Textbox1.ClientID %>').value;
}

</script>
 
Share this answer
 
v2
hey! try
XML
<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[^]
 
Share this answer
 
v2
XML
<script type="text/javascript">

function getTextBoxValue()
{
    var txtValue = document.getElementById(<%= Textbox1.ClientID %>;).value;
    alert(txtValue);
}

</script>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900