Wednesday, 9 November 2016

jQuery Ajax: Move Multiple ListBox Items From One ListBox To Other

11/09/2016 - By Pranav Singh 0

This article will show you how you can move listbox multiple items from one listbox to another list box using jQuery without page refresh. This you can use in MVC, Asp.Net and HTML applications.

So for this article first we will add the jQuery library reference into the header of the page.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

Now check the below jquery code. This will help us to move the listbox items from one list box to other.

<script>
    function MoveListBoxItem(fromId, toId) {
        $("#" + fromId + " option:selected").remove().appendTo("#" + toId);
    }
</script>

Here in above code I have passed the from and to control it. On this bases of these two id we will take decision where we need to move the id. After this we will add two listbox controls and button control.

<table width="100%" border="0">
        <tr>
            <td style="width:48%">Un-Selected</td>
            <td rowspan="2" style="width:4%">
                <input type="button" value=">>" onclick="javascript: MoveListBoxItem('UnSelectedItem', 'SelectedCountryID')" /><br />
                <input type="button" value="<<" onclick="javascript: MoveListBoxItem('SelectedCountryID', 'UnSelectedItem')" />
            </td>
            <td>Selected</td>
        </tr>
        <tr>
            <td>
<select id="UnSelectedItem" multiple="multiple" name="UnSelectedItem" style="width:100%">
    <option value="1">India</option>
    <option value="2">Pakistan</option>
    <option value="3">Nepal</option>
    <option value="4">United States</option>
</select>            </td>
            <td>
<select id="SelectedCountryID" multiple="multiple" name="SelectedCountryID" style="width:100%"></select>
</td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Submit" />
            </td>
        </tr>
    </table>

In above html code I have added two lists and on the button click I have passed the id of controls where we need to move the data. Now lets check the output.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top