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.
<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.
0 comments:
Please let me know your view