The jQuery library provides various options to work
with Textboxes, in this post Asp.Net jQuery get Textbox Values, we shall
see on how to get the values which are entered in an Asp.net Textbox control.
We can set values to Textboxes using
jQuery as follows.
Here is a full example
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head runat="server">
<head runat="server">
<title>TextBox</title>
<link type="text/css"
href="Stylesheet.css"
rel="Stylesheet" />
<script
type="text/javascript"
src="JavaScript/jquery-1.7.2.js"></script>
<script
type="text/javascript"
language="javascript">
$(document).ready(function() {
$('#cmdGetValue').click(function(event) {
event.preventDefault();
alert('Name:
' + $('#txtName').val());
alert('Age:
' + $('#txtAge').val());
alert('Address:
' + $('#txtAddress').val());
alert('Phone:
' + $('#txtPhone').val());
alert('Email:
' + $('#txtEmail').val());
});
});
</script>
</head>
<body>
<form id="frmTextBox" runat="server">
<div id="pageControls">
<table>
<tr>
<td>Name</td>
<td><asp:TextBox
id="txtName"
runat="server"
MaxLength="100"></asp:TextBox></td>
</tr>
<tr>
<td>Age</td>
<td><asp:TextBox
id="txtAge"
runat="server"
MaxLength="25"></asp:TextBox></td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox
ID="txtAddress"
runat="server"
MaxLength="200"></asp:TextBox></td>
</tr>
<tr>
<td>Phone</td>
<td><asp:TextBox
ID="txtPhone"
runat="server"
MaxLength="20"></asp:TextBox></td>
</tr>
<tr>
<td>Email</td>
<td><asp:TextBox
ID="txtEmail"
runat="server"
MaxLength="30"></asp:TextBox></td>
</tr>
<tr>
<td>Get Textbox Values</td>
<td><asp:Button
ID="cmdGetValue"
runat="server"
Text="Get Values" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Run the application, click on the Get Values button, notice that the values in the text boxes are displayed in the message box.
Related Posts
Asp.Net jQuery get Textbox Values
Asp.Net jQuery Textbox set ReadOnly
Asp.Net jQuery Textbox Remove ReadOnly
Asp.Net jQuery Textbox Disable
Asp.Net jQuery Textbox Enable
1 comment:
HI. Nice post. Please also refer the following post to get textbox value using jquery:
http://coding-issues.blogspot.in/2013/10/get-aspnet-textbox-label-value-jquery.html
Post a Comment