Introduction:
In this article I will explain how to create copy or clone
of dropdown list with selected options. Using jQuery it is easy to create clone
of dropdownlist.
<script type="text/javascript">
$(function
() {
$("#btnclone").click(function () {
$('#ddlName').clone().attr('id', 'choices_'
+ $(this).index()).insertAfter("#ddlName");
});
});
</script>
Full Source Code for Sample Application:
<html>
<head id="Head1">
<title>jQuery Clone Dropdown list with
selected value</title>
</head>
<body>
<fieldset style="width:350px">
<legend><strong>Copy or
Clone Dropdown list Using Jquery</strong></legend>
<br />
<select id="ddlName">
<option value="0">select</option>
<option value="Anil">Anil</option>
<option value="Ashish">Ashish</option>
<option value="Anish">Anish</option>
</select><br /><br
/>
<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 () {
$('#ddlName').clone().attr('id', 'choices_'
+ $(this).index()).insertAfter("#ddlName");
});
});
</script></fieldset>
</body>
</html>
0 comments:
Post a Comment