3
* Move selected elements in a list to the target list
5
function moveSelectedById( fromListId, targetListId )
7
var fromList = document.getElementById( fromListId );
8
var targetList = document.getElementById( targetListId );
10
moveSelected( fromList, targetList );
13
function moveSelected( fromList, targetList )
15
if ( fromList.selectedIndex == -1 )
20
while ( fromList.selectedIndex > -1 )
22
option = fromList.options[ fromList.selectedIndex ];
23
fromList.remove( fromList.selectedIndex );
24
targetList.add(option, null);
25
option.selected = true;
30
* Move all elements in a list to the target list
32
function moveAllById( fromListId, targetListId )
34
var fromList = document.getElementById( fromListId );
35
var targetList = document.getElementById( targetListId );
37
moveAll( fromList, targetList );
40
function moveAll( fromList, targetList )
42
for ( var i = fromList.options.length - 1; i >= 0; i-- )
44
option = fromList.options[i];
46
targetList.add(option, null);
47
option.selected = true;
54
function clearListById( listId )
56
var list = document.getElementById( listId );
61
function clearList( list )
63
list.options.length = 0;
67
* Returns true if the list contains the value
69
function listContainsById( listId, value )
71
var list = document.getElementById( listId );
73
return listContains( list, value );
76
function listContains( list, value )
78
for ( var i = 0; i < list.options.length; i++ )
80
if ( list.options[i].value == value )
90
* Marks all elements in a list as selected
92
function selectAllById( listId )
94
var list = document.getElementById( listId );
99
function selectAll( list )
101
for ( var i = 0; i < list.options.length; i++ )
103
list.options[i].selected = true;
108
* Marks all elements in a list as not selected
110
function deselectAllById( listId )
112
var list = document.getElementById( listId );
117
function deselectAll( list )
119
for ( var i = 0; i < list.options.length; i++ )
121
list.options[i].selected = false;