Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JQuery - How to Set Get Textbox Value using jQuery

Sep 2, 2012
Introduction

Here I will explain how to get textbox value using jquery or how to set textbox value in jquery.

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.

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
UserName:

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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

6 comments :

Mossad@1962 said...

hey thanks .....................

Unknown said...

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......

Unknown said...

Hi All,

If any asp control is dragged & dropped into asp TextBox, Source Code must display in TextBox using jquery. Pls help me.

Anonymous said...

how to validate textbox inside gridview using jquery

Unknown said...

i have to fetch the values from ASP textbox not html input type
plz rply

Anonymous said...

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.