PDA

View Full Version : انتقال از لیست باکس به لیست باکس دیگر



هوشمند
یک شنبه 10 خرداد 1388, 12:02 عصر
سلام من می خواهم چندتایی یا همه آنچه در یک لیست است را به ایست دیگر انتقال دهم لطفا کد راهنمایی بفرمایید

function addOne(){
selIdx = document.getElementById('agentSource').selectedInd ex;
textval = document.getElementById('agentSource').options[selIdx].text;
val = document.getElementById('agentSource').options[selIdx].value;
//window.alert(selIdx);
//window.alert(textval);
//window.alert(val);
document.getElementById('agentDestination').option s[document.getElementById('agentDestination').length] =
new Option(textval,val,false,true);
}
function removeOne(){
var elSel = document.getElementById('agentDestination');
var i;
for (i = elSel.length - 1; i>=0; i--) {
if (elSel.options[i].selected) {
elSel.remove(i);

این کد تک تک انتقال می دهد که من نوشتم.

violet
یک شنبه 17 خرداد 1388, 13:13 عصر
این رو امتحان کن:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ListBox</title>
<script type="text/javascript">
var srclb, destlb;
var Flag;
function moveAll(evt) {
if (evt.id == 'btnSel' || evt.id == 'btnADitem') {
srclb = document.getElementById('lboxSource');
destlb = document.getElementById('lboxdest');
}
else if (evt.id == 'btnDesel' || evt.id == 'btnRMitem') {
srclb = document.getElementById('lboxdest');
destlb = document.getElementById('lboxSource');
}
if (srclb != null && destlb != null) {
Flag = true;
while (Flag) {
Flag = false;
for (var i = 0; i < srclb.length; i++) {
if (evt.id == 'btnADitem' || evt.id == 'btnRMitem') {
if (srclb[i].selected) {
exChange(i);
}
}
else if (evt.id == 'btnSel' || evt.id == 'btnDesel') {
exChange(i);
}
}
}
}
}
function exChange(iVal) {
destlb.appendChild(srclb[iVal].cloneNode(true));
srclb.removeChild(srclb[iVal]); Flag = true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<select id="lboxSource" multiple="multiple">
<option>a</option>
<option>b</option>
<option>v</option>
<option>z</option>
</select>
</td>
<td style="width: 31px">
<input id="btnDesel" title="DeselectAll" type="button" style="position: relative;
left: 3px; width: 27px; top: 88px; height: 27px;" onclick="moveAll(this);" value="««" />
<input id="btnRMitem" title="Remove Item" type="button" style="position: relative;
left: 3px; width: 27px; top: 35px; height: 25px;" onclick="moveAll(this);" value="«" />
<input id="btnADitem" title="Add Item" type="button" style="position: relative; left: 3px;
width: 26px; top: -23px; height: 29px;" onclick="moveAll(this);" value="»" />
<input id="btnSel" title="SelectAll" type="button" style="position: relative; left: 3px;
width: 25px; top: -83px; height: 28px;" onclick="moveAll(this);" value="»»" />
</td>
<td>
<select id="lboxDest" multiple="multiple">
</select>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>