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 Clone (Copy) Dropdown List with Selected Value

Jul 9, 2014
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.

If we want to clone dropdown list using jQuery we need to write the code like as shown below


$('#ddlcountry').clone().attr('id', 'choices_' + $(this).index()).insertAfter("#ddlcountry");


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


Clone Dropdown: 

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

5 comments :

Unknown said...

Nice Article sir, Please tell me how to find ID of cloned ddl.

Fahim Ahmed said...

How to save data of each ddl in database?
pls help

nikhil said...

good

Anonymous said...

very good article...

Anonymous said...

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.

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.