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 Dropdown list Values using jQuery & Bind New Values

Mar 19, 2014
Introduction

Here I will explain how to clear dropdown values using
jQuery and bind new values to dropdownlist using jQuery or clear items of dropdownlist using jQuery.


To clear dropdown values and bind new values to dropdownlist using jQuery we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Clear dropdown values in jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
function cleardropdown() {
// To clear dropdown values we need to write code like as shown below
$('#ddluser').empty();
// Bind new values to dropdown
$('#ddluser').each(function() {
// Create option
var option = $("<option />");
option.attr("value", '0').text('Select User');
$('#ddluser').append(option);
});
}
</script>
</head>
<body>
<form id="form1">
<div>
<b>Select User:</b>
<select id="ddluser">
<option value="0">Select user</option>
<option value="1">Suresh Dasari</option>
<option value="2">Rohini Dasari</option>
<option value="3">Praveen Alavala</option>
<option value="4">Sateesh A</option>
</select>
<input type="button" id="btnclear" onclick="cleardropdown()" value="Clear Dropdown" />
</div>
</form>
</body>
</html>
Demo

For live demo click below button



Select User:


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 :

Unknown said...

nice....

Unknown said...

Sir, I am creating a website in which user can download the android applications, I need a code by which i can find how many people download a perticular application, I have 50 applications for download.

Anonymous said...

Very good programming.

Vishnu Das said...

hai suresh...its very good

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.