To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / public / javascripts / select_list_move.js @ 1255:90d92ad3fc59
History | View | Annotate | Download (1.87 KB)
| 1 |
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5); |
|---|---|
| 2 |
|
| 3 |
function addOption(theSel, theText, theValue) |
| 4 |
{
|
| 5 |
var newOpt = new Option(theText, theValue); |
| 6 |
var selLength = theSel.length;
|
| 7 |
theSel.options[selLength] = newOpt; |
| 8 |
} |
| 9 |
|
| 10 |
function swapOptions(theSel, index1, index2) |
| 11 |
{
|
| 12 |
var text, value;
|
| 13 |
text = theSel.options[index1].text; |
| 14 |
value = theSel.options[index1].value; |
| 15 |
theSel.options[index1].text = theSel.options[index2].text; |
| 16 |
theSel.options[index1].value = theSel.options[index2].value; |
| 17 |
theSel.options[index2].text = text; |
| 18 |
theSel.options[index2].value = value; |
| 19 |
} |
| 20 |
|
| 21 |
function deleteOption(theSel, theIndex) |
| 22 |
{
|
| 23 |
var selLength = theSel.length;
|
| 24 |
if(selLength>0) |
| 25 |
{
|
| 26 |
theSel.options[theIndex] = null;
|
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
function moveOptions(theSelFrom, theSelTo) |
| 31 |
{
|
| 32 |
|
| 33 |
var selLength = theSelFrom.length;
|
| 34 |
var selectedText = new Array(); |
| 35 |
var selectedValues = new Array(); |
| 36 |
var selectedCount = 0; |
| 37 |
|
| 38 |
var i;
|
| 39 |
|
| 40 |
for(i=selLength-1; i>=0; i--) |
| 41 |
{
|
| 42 |
if(theSelFrom.options[i].selected)
|
| 43 |
{
|
| 44 |
selectedText[selectedCount] = theSelFrom.options[i].text; |
| 45 |
selectedValues[selectedCount] = theSelFrom.options[i].value; |
| 46 |
deleteOption(theSelFrom, i); |
| 47 |
selectedCount++; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
for(i=selectedCount-1; i>=0; i--) |
| 52 |
{
|
| 53 |
addOption(theSelTo, selectedText[i], selectedValues[i]); |
| 54 |
} |
| 55 |
|
| 56 |
if(NS4) history.go(0); |
| 57 |
} |
| 58 |
|
| 59 |
function moveOptionUp(theSel) { |
| 60 |
var index = theSel.selectedIndex;
|
| 61 |
if (index > 0) { |
| 62 |
swapOptions(theSel, index-1, index);
|
| 63 |
theSel.selectedIndex = index-1;
|
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
function moveOptionDown(theSel) { |
| 68 |
var index = theSel.selectedIndex;
|
| 69 |
if (index < theSel.length - 1) { |
| 70 |
swapOptions(theSel, index, index+1);
|
| 71 |
theSel.selectedIndex = index+1;
|
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
// OK
|
| 76 |
function selectAllOptions(id) |
| 77 |
{
|
| 78 |
var select = $('#'+id);/* |
| 79 |
for (var i=0; i<select.options.length; i++) {
|
| 80 |
select.options[i].selected = true;
|
| 81 |
}*/
|
| 82 |
select.children('option').attr('selected', true); |
| 83 |
} |