Цитата(AKS @ 7.11.2006, 17:03 ) | Наверняка будет достаточно подставить вашу функцию sort_opt (из первоначального варианта сценария) вместо функции sorter... |
так и сделал 
конечный код:
| Код | <html> <head> <title>Multy Select</title>
<script type="text/javascript"> function replacer(select1, select2, bool) { var element; if(bool) { while(element = select1.firstChild) select2.appendChild(select1.removeChild(element)); } else { for(var i = 0; element = select1.options[i]; i++) { if(element.selected) { select2.appendChild(element); element.selected = bool; } } } }
function mover(o, bool) { var e = o.options, i = o.selectedIndex, n = (bool) ? i - 1 : i + 1; (i > -1 && n >= 0 && n < o.length) ? (o.insertBefore(o.removeChild(e[i]), e[n]), o.selectedIndex = n) : ''; }
sort_opt=function (x,y){ if (x.text==y.text) return 0 else if (x.text<y.text) return -1 else if (x.text>y.text) return 1; }
function sorter(x, y) { x = (+x.value), y = (+y.value); return ((x > y) ? 1 : (x < y) ? -1 : 0); } function orderer(o) { var a = []; for(var i = 0, l = o.length; i < l; i++) a[a.length] = o.options[i]; a.sort(sort_opt); for(i = 0; i < l; i++) o.appendChild(a[i]); }
</script>
</head>
<body> <div> <form mathod="POST" action="http://localhost:8066/index3" name="TForm1_select" onsubmit="javasript:alert('form post')">
<table border="0"><tr><td>
<select name="select_left" multiple="multiple" size="10" id="select_left_id" ondblclick="javascript:replacer(document.getElementById('select_left_id'), document.getElementById('select_right_id'), false);"> <option value="1">№ 1</option> <option value="2">№ 2</option> <option value="3">№ 3</option> <option value="4">№ 4</option> <option value="5">№ 5</option> <option value="6">№ 6</option> <option value="7">№ 7</option> <option value="8">№ 8</option> <option value="9">№ 9</option> <option value="10">№ 10</option> </select> </td> <td> <button name="button_to_right" id="id_button_to_right" onclick="replacer(document.getElementById('select_left_id'), document.getElementById('select_right_id'), false); return false;" style="display:block; margin-bottom:15px"> > </button> <button name="button_all_to_right" id="id_button_all_to_right" onclick="replacer(document.getElementById('select_left_id'), document.getElementById('select_right_id'), true); return false;" style="display:block; margin-bottom:15px"> All>> </button>
<button name="button_all_to_left" id="id_button_all_to_left" onclick="replacer(document.getElementById('select_right_id'), document.getElementById('select_left_id'), true); return false;" style="display:block; margin-bottom:15px"> << All </button> <button name="button_to_left" id="id_button_to_left" onclick="replacer (document.getElementById('select_right_id'), document.getElementById('select_left_id'), false); return false;" style="display:block; margin-bottom:15px"> < </button>
</td> <td> <select name="select_right" multiple="multiple" size="10" id="select_right_id" ondblclick="replacer(document.getElementById('select_right_id'), document.getElementById('select_left_id'), false); orderer(document.getElementById('select_left_id'));"> </select> </td> <td> <img src="arrow_up.gif" onclick="mover(document.getElementById('select_right_id'), true)" style="display:block; margin-bottom:15px"/> <img src="arrow_down.gif" onclick="mover(document.getElementById('select_right_id'), false)" style="display:block; margin-bottom:15px"/> </td> </tr></table>
<input type="submit" value="send"/>
</form> </div> </body> </html>
|
|