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.
Description:
In previous articles I explained jQuery merge multiple tables into single table, jQuery check if string contains specific word, jQuery add border to images in webpage, jQuery show loading image in pageload, jQuery hide div elements after 5 seconds, jQuery convert am / pm time to 24 hours time, jQuery print div content with css and many articles relating to JQuery, JavaScript. Now I will explain how to clear dropdown values using jQuery and bind new values to dropdownlist using jQuery.
In previous articles I explained jQuery merge multiple tables into single table, jQuery check if string contains specific word, jQuery add border to images in webpage, jQuery show loading image in pageload, jQuery hide div elements after 5 seconds, jQuery convert am / pm time to 24 hours time, jQuery print div content with css and many articles relating to JQuery, JavaScript. Now I will explain how to clear dropdown values using jQuery and bind new values to 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
|
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. |
|||
|
|||
4 comments :
nice....
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.
Very good programming.
hai suresh...its very good
Note: Only a member of this blog may post a comment.