-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistBoxReorder.js
More file actions
51 lines (38 loc) · 1.35 KB
/
listBoxReorder.js
File metadata and controls
51 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function ItemUpOrDown(ListBoxId, interval)
{
var listControl = document.getElementById(ListBoxId);
var listItemsCount = listControl.length;
var selectedItemIndex = listControl.selectedIndex;
var workIndex = selectedItemIndex - interval;
var x = 0;
if(interval == null || selectedItemIndex < 0 || workIndex < 0 || workIndex >= listItemsCount)
return false;
// Add new items
for(x = 0; x < listItemsCount; x++)
{
var newOptionElement = document.createElement("option");
var i = 0;
switch(x)
{
case workIndex:
newOptionElement.setAttribute("value", listControl.options[selectedItemIndex].value);
newOptionElement.innerText = listControl.options[selectedItemIndex].text;
break;
case (workIndex + interval):
i = x - interval;
if(i < 0){i = i * (-1);}
newOptionElement.setAttribute("value", listControl.options[x - interval].value);
newOptionElement.innerText = listControl.options[x - interval].text;
break;
default:
newOptionElement.setAttribute("value", listControl.options[x].value);
newOptionElement.innerText = listControl.options[x].text;
break;
}
listControl.appendChild(newOptionElement);
}
// Remove old items
for(x = 0; x < listItemsCount; x++){listControl.options[0].remove();}
listControl.options[workIndex].selected = "selected";
return true;
}