Determine if the item value= "Paravalue" exists in the Select option
//1. Determine if the value= "Paravalue" item exists in the SELECT optionfunctionJsselectisexititem (Objselect, objitemvalue) {varIsexit =false; for(vari = 0; i < objSelect.options.length; i++) { if(Objselect.options[i].value = =objitemvalue) {Isexit=true; Break; } } returnIsexit; }
Add an item to the Select option
//2. Add an item to the Select optionfunctionJsadditemtoselect (Objselect, Objitemtext, objitemvalue) {//determine if there is if(Jsselectisexititem (Objselect, Objitemvalue)) {alert ("The value of the item already exists"); } Else { varVaritem =NewOption (Objitemtext, Objitemvalue); ObjSelect.options.add (Varitem); Alert ("Join successfully"); } }
Remove an item from the Select option
//3. Remove an item from the Select optionfunctionJsremoveitemfromselect (Objselect, objitemvalue) {//determine if there is if(Jsselectisexititem (Objselect, Objitemvalue)) { for(vari = 0; i < objSelect.options.length; i++) { if(Objselect.options[i].value = =objitemvalue) {ObjSelect.options.remove (i); Break; }} alert ("Successfully deleted"); } Else{alert ("The item does not exist in this select"); } }
Delete selected items in select
// 4. Delete the selected item in select function Jsremoveselecteditemfromselect (objselect) { var length = Objselect.options.length-1; for (var i = length; I >= 0; i--) { iftrue) { NULL ; } } }
Modify the Select option in Value = " Paravalue " the text is " Paratext "
//5. Modify the text of value= "Paravalue" in the Select option to "Paratext"functionJsupdateitemtoselect (Objselect, Objitemtext, objitemvalue) {//determine if there is if(Jsselectisexititem (Objselect, Objitemvalue)) { for(vari = 0; i < objSelect.options.length; i++) { if(Objselect.options[i].value = =objitemvalue) {Objselect.options[i].text=Objitemtext; Break; }} alert ("Successful Modification"); } Else{alert ("The item does not exist in this select"); } }
set text in select = " Paratext " The first item is selected
//6. Set the first item of text= "Paratext" in Select to be selectedfunctionJsselectitembyvalue (Objselect, objitemtext) {//determine if there is varIsexit =false; for(vari = 0; i < objSelect.options.length; i++) { if(Objselect.options[i].text = =Objitemtext) {objselect.options[i].selected=true; Isexit=true; Break; } } //Show out Results if(isexit) {alert ("Selected successfully"); } Else{alert ("The item does not exist in this select"); } }
set value in select = " Paravalue " the item is selected
// 7. Set the item of value= "Paravalue" in Select to select Document.all.objSelect.value = Objitemvalue;
gets the value of the currently selected item of select
// 8. Gets the value of the current selected item of select var currselectvalue = Document.all.objSelect.value;
Gets the text of the current selected item of select
// 9. Gets the text of the current selected item of select var currselecttext = Document.all.objselect.options[document.all.objselect.selectedindex].text;
Gets the index of the current selected item of select
// 10. Get the index of the current selected item of select var currselectindex = Document.all.objSelect.selectedIndex;
Empty the Select item
// 11. Clear the Select item document.all.objSelect.options.length = 0;