Introduction:
Here I will explain how to use jQuery to copy or clone dropdown list with selected option or jQuery copy dropdown value to another dropdown.
Description:
In previous articles I explained jQuery get radio button selected value by name, jQuery pdf viewer plugin examples, jQuery news ticker plugin examples, jQuery dropdown with images, jQuery Countdown timer script example and many articles relating to jQuery in asp.net. Now I will explain how to get clone dropdown list using jQuery.
In previous articles I explained jQuery get radio button selected value by name, jQuery pdf viewer plugin examples, jQuery news ticker plugin examples, jQuery dropdown with images, jQuery Countdown timer script example and many articles relating to jQuery in asp.net. Now I will explain how to get clone dropdown list using jQuery.
If we
want to clone dropdown list using jQuery
we need to write the code like as shown below
|
If
you want to check it in complete sample we need to write the code like as shown
below
<html>
<head id="Head1">
<title>jQuery Clone Dropdown list with selected value</title>
</head>
<body>
<select id="ddlcountry">
<option value="0">select</option>
<option value="india">india</option>
<option value="usa">usa</option>
<option value="canada">canada</option>
</select>
<input type="button" id="btnclone" value="Clone Dropdown">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function()
{
$("#btnclone").click(function() {
$('#ddlcountry').clone().attr('id', 'choices_'
+ $(this).index()).insertAfter("#ddlcountry");
});
});
</script>
</body>
</html>
|
Live
Demo
To
check live demo try to click on below button to create new dropdown list with
selected value
|
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. |
|||
|
|||
5 comments :
Nice Article sir, Please tell me how to find ID of cloned ddl.
How to save data of each ddl in database?
pls help
good
very good article...
Sir, I am having a similar requirement but with subsequent dropdown list, the selected items in previous dropdown lists need not be present.Please shed light.
Note: Only a member of this blog may post a comment.