In one of the modules I have coded ,I need to transfer items from one ListBox(Select) to another.I have put the same code here.
Here listBox1 and listBoxb2 are the two listboxes and btnTransfer and btnTransferBack are the two buttons one whose click we
will transfer the selected items.I have also put a check on the maximum number of items that can listbox2 can contain(in this case it is 20).
<select id="listBox1" style="width:180px;height:210px" size=10 multiple="multiple"/>
<select id="listBox2" style="width:180px;height:210px" size=10 multiple="multiple"/>
<button id="btnTransfer" onclick="listbox_moveacross('listBox1','listBox2', 20);return false;"> </button>
<button id="btnTransferBack" onclick="listbox_moveacross('listBox2', 'listBox1', -1);return false;"> </button>
<script type="text/javascript">
function listbox_moveacross(sourceID, destID, limit) {
if (limit > -1) {
var startIndex = 0;
var endIndex = 0;
endIndex = limit - $('#' + destID + ' option').length;
$('#' + sourceID + ' option:selected').slice(startIndex, endIndex).appendTo('#' + destID);
}
else {
$('#' + sourceID + ' option:selected').appendTo('#' + destID);
}
}
</script>
6dc0bf29-1410-4974-b712-5e243d7368e0|0|.0
Categories:
ASP.NET, Jquery
30. December 2011
Tags:
Jquery Listbox Manipulate, Move listbox Items, Transfer ListBox items