function getSelectCheckedValue(selectName){ var i = 0; var select = document.getElementById(selectName); for(; i < select.options.length ; i = i + 1){ if( select.options[i].selected ){ return select.options[i].value; } } if( i == select.options.length ){ return ""; } } function getSelectCheckedText(selectName){ var i = 0; var select = document.getElementById(selectName); for(; i < select.options.length ; i = i + 1){ if( select.options[i].selected ){ return select.options[i].text; } } if( i == select.options.length ){ return ""; } } function checkedSelectByValue(selectName, value){ var i = 0; var select = document.getElementById(selectName); for(i = 0 ; i < select.options.length ; i = i + 1){ if( select.options[i].value == value ){ select.options[i].selected = true; } } } function deleteOptions(selectName){ var select = document.getElementById(selectName); var pos = select.selectedIndex; while(pos != -1){ select.options[pos] = null; pos = select.selectedIndex; } } function deleteAllOptions(selectName){ var select = document.getElementById(selectName); for(var pos = select.options.length - 1; pos >= 0 ; pos--){ select.options[pos] = null; } } function addOption(selectName, pos, value, text){ var select = document.getElementById(selectName); if(pos >= select.options.length ){ pos = select.options.length;} if(pos < 0){ pos = 0;} var duplicated = false; for( var j = 0; j < select.options.length ; j = j + 1){ if(value == select.options[j].value){ duplicated = true; break; } } if(duplicated){ return; }else{ for( var i = select.options.length - 1 ; i >= pos ; i = i - 1 ){ select.options[i + 1] = new Option(select.options[i].text, select.options[i].value); } } select.options[pos] = new Option(text, value); select.selectedIndex = pos; } function moveOption(selectName ,up) { var select = document.getElementById(selectName); var pos = select.selectedIndex; if (pos == -1){ return; }else { var nextPos = pos + ( up ? -1 : 1); if (nextPos < 0){ nextPos = 0; } if (nextPos >= select.options.length){ nextPos = select.options.length - 1; } var oldVal = select.options[pos].value; var oldText = select.options[pos].text; select.options[pos].value = select.options[nextPos].value; select.options[pos].text = select.options[nextPos].text; select.options[nextPos].value = oldVal; select.options[nextPos].text = oldText; if (up){ select.selectedIndex = nextPos; }else{ select.selectedIndex = nextPos; } } } function transverseSelectedOptions(selectNameFrom, selectNameTo){ var i = 0; var select = document.getElementById(selectNameFrom); var len = select.options.length; for(; i < select.options.length ; i = i + 1){ if( select.options[i].selected && select.options[i].value != ""){ addOption(selectNameTo, len, select.options[i].value, select.options[i].text); select.options[i].selected = false; } } } function check_optionChange(selectNameHost, selectNameCust, optionArrayHost, optionArrayKey, optionArrayText){ var sl2 = document.getElementById(selectNameCust); var k = 1; sl2.options.length = k; var hostValue = getSelectCheckedValue(selectNameHost); if(hostValue == ""){ return; } for(var i = 0 ; i < optionArrayHost.length ; i++){ if(hostValue == optionArrayHost[i]){ sl2.options[k] = new Option(optionArrayText[i], optionArrayKey[i]); k++; } } } function collectMultipleSelect(selectName, textFieldName){ document.getElementById(textFieldName).value = ""; var tmp = ""; var select = document.getElementById(selectName); for (var i = 0; i < select.options.length; i = i + 1) { if(tmp != ""){ tmp = tmp + ","; } tmp = tmp + select.options[i].value; } document.getElementById(textFieldName).value = tmp; }