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

How to Clear Textbox Value with jQuery

Apr 30, 2013
Introduction

Here I will explain How to use jQuery to clear textbox value or simple jQuery code snippet to clear textbox value using jQuery.

Description

To clear all textbox values using jQuery we need to write the code like as shown below

$(function () {
$('#btnClear').click(function () {
$('input[type=text]').each(function () {
$(this).val('');
})
})
})
To clear Particular textbox using jQuery we need to write the code like as shown below

$(function () {
$('#btnClear').click(function () {
$('#txtName').val('');
})
})
For complete example check below code


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Clear Textbox using jQuery</title>
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btnClear').click(function () {
$('input[type=text]').each(function () {
$(this).val('');
})
})
$('#btnclr').click(function () {
$('#txtuser').val('');
})
})
</script>
</head>
<body>
<div>
<b>Enter Text:</b>
<input type="text" id="txtuser" />
<input type="text" id="txtName" />
<input type="button" id="btnclr" value="Clear First Textbox" />
<input type="button" id="btnClear" value="Clear All Textboxes" />
</div>
</body>
</html>
Live Demo

To check live demo try to enter text in below textboxes and click on buttons



Enter Text:

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

4 comments :

jaan09 said...

nice

asp.net training said...

nice blog for readers.

Anonymous said...

Sir, How to print the content of div using javascript? pls help me

Unknown said...

sorry but my code is not working

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.