Du bist hier: Snippet-Verzeichnis » HTML/JavaScript (65)
Sprache:

advance List box control

Sprache: English
Programmiersprache: JavaScript
Veröffentlicht von: gutlam [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1533


Beschreibung

add, modify, delete an array which is shown in a list box object

Code

1 function doAddTextToSelect(sourceObj, destObj) { 2 if (sourceObj.value!='') { 3 destObj.options[destObj.length] = new Option(sourceObj.value, sourceObj.value) //text, value 4 sourceObj.value = ''; 5 } 6 } 7 function doEditSelect(sourceObj) { 8 var selectIndex = sourceObj.selectedIndex; 9 if (selectIndex > 0) { 10 result = window.prompt("Please modify the selected option:\n(Click OK to confirm)", sourceObj.options[selectIndex].value) 11 if (result !=null) { 12 sourceObj.options[selectIndex].text = result; 13 sourceObj.options[selectIndex].value = result; 14 } 15 } 16 } 17 function doRemoveSelect(sourceObj) { 18 var tmpValueList = ''; 19 var tmpTextList = '--------------------------------------------'; 20 var arrayValueList; 21 var arrayTextList; 22 var delimiter = '^'; 23 24 for (var i=1;i<sourceObj.length;i++) { 25 if (sourceObj.options[i].selected == true) { 26 } else { 27 tmpValueList += delimiter + sourceObj.options[i].value; 28 tmpTextList += delimiter + sourceObj.options[i].text; 29 } 30 } 31 32 arrayValueList = tmpValueList.split(delimiter); 33 arrayTextList = tmpTextList.split(delimiter); 34 35 sourceObj.options.length = 0; 36 for (var i=0;i<arrayValueList.length;i++) { 37 sourceObj.options[i] = new Option( arrayTextList[i], arrayValueList[i]) //text, value 38 } 39 } 40 function doUpDownSelect(sourceObj, cmd) { 41 var tmpValueList = ''; 42 var tmpTextList = ''; 43 var selectIndex = sourceObj.selectedIndex; 44 if (cmd == 'up') { 45 if (selectIndex > 1 ) { 46 tmpValueList = sourceObj.options[selectIndex-1].value; 47 tmpTextList = sourceObj.options[selectIndex-1].text; 48 sourceObj.options[selectIndex-1].value = sourceObj.options[selectIndex].value; 49 sourceObj.options[selectIndex-1].text = sourceObj.options[selectIndex].text; 50 sourceObj.options[selectIndex].value = tmpValueList; 51 sourceObj.options[selectIndex].text = tmpTextList; 52 sourceObj.options[selectIndex-1].selected = true; 53 } 54 } 55 if (cmd == 'dn') { 56 if (selectIndex < sourceObj.length-1 && selectIndex >=1 ) { 57 tmpValueList = sourceObj.options[selectIndex+1].value; 58 tmpTextList = sourceObj.options[selectIndex+1].text; 59 sourceObj.options[selectIndex+1].value = sourceObj.options[selectIndex].value; 60 sourceObj.options[selectIndex+1].text = sourceObj.options[selectIndex].text; 61 sourceObj.options[selectIndex].value = tmpValueList; 62 sourceObj.options[selectIndex].text = tmpTextList; 63 sourceObj.options[selectIndex+1].selected = true; 64 } 65 } 66 } 67

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS