You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. // JavaScript Document
  2. function listbox_move(listID, direction) {
  3. var listbox = document.getElementById(listID);
  4. var selIndex = listbox.selectedIndex;
  5. if (-1 == selIndex) {
  6. alert("Please select an option to move.");
  7. return;
  8. }
  9. //alert(listbox.options.length);
  10. //listbox.selectedIndex =listbox.options.length;
  11. var increment = -1;
  12. if (direction == 'up')
  13. increment = -1;
  14. else
  15. increment = 1;
  16. if ((selIndex + increment) < 0 ||
  17. (selIndex + increment) > (listbox.options.length - 1)) {
  18. return;
  19. }
  20. var selValue = listbox.options[selIndex].value;
  21. var selText = listbox.options[selIndex].text;
  22. listbox.options[selIndex].value = listbox.options[selIndex + increment].value
  23. listbox.options[selIndex].text = listbox.options[selIndex + increment].text
  24. listbox.options[selIndex + increment].value = selValue;
  25. listbox.options[selIndex + increment].text = selText;
  26. listbox.selectedIndex = selIndex + increment;
  27. }
  28. function listbox_selectall(listID, isSelect) {
  29. var listbox = document.getElementById(listID);
  30. for (var count = 0; count < listbox.options.length; count++) {
  31. listbox.options[count].selected = isSelect;
  32. }
  33. }
  34. function listbox_moveacross(sourceID, destID) {
  35. var src = document.getElementById(sourceID);
  36. var dest = document.getElementById(destID);
  37. for (var count = 0; count < src.options.length; count++) {
  38. if (src.options[count].selected == true) {
  39. var option = src.options[count];
  40. var newOption = document.createElement("option");
  41. newOption.value = option.value;
  42. newOption.text = option.text;
  43. newOption.selected = true;
  44. try {
  45. dest.add(newOption, null); //Standard
  46. src.remove(count, null);
  47. } catch (error) {
  48. dest.add(newOption); // IE only
  49. src.remove(count);
  50. }
  51. count--;
  52. }
  53. }
  54. }