- Get link
- X
- Other Apps
jQuery Clone (Copy) Dropdown List with Selected Value
By: Suresh Dasari Jul 9, 2014
Categories: Javascript , JQuery
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
|
Comments
Post a Comment