Introduction:
Description:
In previous post I explained split the string using split function in jquery and many articles relating to JQuery. Now I will explain how to get or set textbox value in JQuery.
In previous post I explained split the string using split function in jquery and many articles relating to JQuery. Now I will explain how to get or set textbox value in JQuery.
If
we want to get textbox value in jquery or if we need to set
value in textbox using jquery we need to write the
code like as shown below
// Get textbox value
$('#txtName').val()
// Set textbox value
$('#txtName').val("your
message")
|
If
you want check this code in sample check below code
Example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"
runat="server">
<title>Get or Set textbox value in JQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#btnGet').click(function() {
//Get textbox value
alert($('#txtName').val());
})
$('#btnSet').click(function() {
// Set value in textbox
$('#txtName').val("Suresh")
alert($('#txtName').val());
})
});
</script>
</head>
<body>
<form id="form1"
runat="server">
<table>
<tr><td align="right" style=" font-family:Verdana; font-size:10pt"><b>UserName:</b></td>
<td> <input type="text" id="txtName" value="Aspdotnet-Suresh.com" /></td>
</tr>
<tr><td><input type="button" id="btnGet" value="Get Text" /></td>
<td> <input type="button" id="btnSet" value="SET To 'Suresh'" /></td>
</tr>
</table>
</form>
</body>
</html>
|
Demo
To check demo click
on buttons and see the output
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
6 comments :
hey thanks .....................
if the textbox is in grid view than how to get text box value????....i mean i want display text box value in pop up using jquery..and my text box is in grid view......
Hi All,
If any asp control is dragged & dropped into asp TextBox, Source Code must display in TextBox using jquery. Pls help me.
how to validate textbox inside gridview using jquery
i have to fetch the values from ASP textbox not html input type
plz rply
Note: Only a member of this blog may post a comment.