// =================================================================== // Author: Matt Kruse // WWW: http://www.mattkruse.com/ // =================================================================== // ------------------------------------------------------------------- // selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false) // This is a general function used by the select functions below, to // avoid code duplication // ------------------------------------------------------------------- function selectUnselectMatchingOptions(obj,regex,which,only) { if (window.RegExp) { if (which == "select") { var selected1=true; var selected2=false; } else if (which == "unselect") { var selected1=false; var selected2=true; } else { return; } var re = new RegExp(regex); for (var i=0; i (b.text+"")) { return 1; } return 0; } ); for (var i=0; i 0) { for (var i=0; i 0) { for (var i=0; i... // Added by Toby Kurien // ------------------------------------------------------------------- function selectOptionByDefault(obj) { if (obj.options && obj.options.length > 0 && obj.attributes['default'] != null) { var val = obj.attributes['default'].value; selectOptionByValue(obj, val); } } // ------------------------------------------------------------------- // selectAllOptions(select_object) // This function takes a select box and selects all options (in a // multiple select object). This is used when passing values between // two select boxes. Select all options in the right box before // submitting the form so the values will be sent to the server. // ------------------------------------------------------------------- function selectAllOptions(obj) { if (obj.options.length == 0) { // Added by Toby Kurien: Add a blank option if there are none in the // select box, so that a blank value is sent to the server obj.options[0] = new Option('', '', true, true); } for (var i=0; i object as follows: // onDblClick="moveSelectedOptions(this,this.form.target) // This way, when the user double-clicks on a value in one box, it // will be transferred to the other (in browsers that support the // onDblClick() event handler). // ------------------------------------------------------------------- var dupMsg; function moveSelectedOptionsAllowDuplicates(from,to, msg) { dupMsg = msg; moveSelectedOptionsAllowDuplicatesAction(from,to); } function moveSelectedOptionsAllowDuplicatesAction(from,to) { // Unselect matching options, if required if (arguments.length>3) { var regex = arguments[3]; if (regex != "") { unSelectMatchingOptions(from,regex); } } // Move them over for (var i=0; i=0; i--) { var o = from.options[i]; if (o.selected) { from.options[i] = null; } } if ((arguments.length<3) || (arguments[2]==true)) { sortSelect(from); sortSelect(to); } from.selectedIndex = -1; to.selectedIndex = -1; } function copySelectedOptionsAllowDuplicates(from,to, msg) { dupMsg = msg; copySelectedOptionsAllowDuplicatesAction(from,to, false); } function copySelectedOptionsAllowDuplicatesAction(from,to) { // Unselect matching options, if required if (arguments.length>3) { var regex = arguments[3]; if (regex != "") { unSelectMatchingOptions(from,regex); } } // Move them over for (var i=0; i3) { var regex = arguments[3]; if (regex != "") { unSelectMatchingOptions(from,regex); } } // Move them over for (var i=0; i=0; i--) { var o = from.options[i]; if (o.selected) { from.options[i] = null; } } if ((arguments.length<3) || (arguments[2]==true)) { sortSelect(from); sortSelect(to); } from.selectedIndex = -1; to.selectedIndex = -1; } function inList(list, option){ for (var i=0; i=0; i--) { var o = from.options[i]; if (o.selected) { from.options[i] = null; } } } // ------------------------------------------------------------------- // copySelectedOptions(select_object,select_object[,autosort(true/false)]) // This function copies options between select boxes instead of // moving items. Duplicates in the target list are not allowed. // ------------------------------------------------------------------- function copySelectedOptions(from,to) { var options = new Object(); for (var i=0; i= 0; i--) { selectBox.options[i] = null; }; } // ------------------------------------------------------------------- // swapOptions(select_object,option1,option2) // Swap positions of two options in a select list // ------------------------------------------------------------------- function swapOptions(obj,i,j) { var o = obj.options; var i_selected = o[i].selected; var j_selected = o[j].selected; var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected); var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected); o[i] = temp2; o[j] = temp; o[i].selected = j_selected; o[j].selected = i_selected; } // ------------------------------------------------------------------- // moveOptionUp(select_object) // Move selected option in a select list up one // ------------------------------------------------------------------- function moveOptionUp(obj) { // If > 1 option selected, do nothing var selectedCount=0; for (i=0; i 1) { return; } // If this is the first item in the list, do nothing var i = obj.selectedIndex; if (i == 0) { return; } swapOptions(obj,i,i-1); obj.options[i-1].selected = true; } // ------------------------------------------------------------------- // moveOptionDown(select_object) // Move selected option in a select list down one // ------------------------------------------------------------------- function moveOptionDown(obj) { // If > 1 option selected, do nothing var selectedCount=0; for (i=0; i 1) { return; } // If this is the last item in the list, do nothing var i = obj.selectedIndex; if (i == (obj.options.length-1)) { return; } swapOptions(obj,i,i+1); obj.options[i+1].selected = true; }