Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Sunday, 12 April 2015

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.

Following Script is used to Create Copy or clone of dropdown list:
<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