This code is transferred from old zizhu's Java century network
Http://www.java2000.net/viewthread.jsp? Tid = 6704
// Clear the drop-down table. Except for the first row, select XXX]
Function clearoption (OBJ ){
For (I = obj. Options. Length-1; I> 0; I --){
OBJ. Options [I] = NULL;
}
OBJ. selectedindex = 0;
}
// Clear all the drop-down tables
Function clearoptionall (OBJ ){
For (I = obj. Options. Length-1; I> = 0; I --){
OBJ. Options [I] = NULL;
}
}
// Select all
Function selectoptionall (OBJ ){
For (I = obj. Options. Length-1; I> = 0; I --){
OBJ. Options [I]. Selected = true;
}
}
// Add Option
// Value and text are the option parameters respectively.
// Selected indicates whether to select
Function appendoption (OBJ, value, text, selected ){
VaR o = New Option (text, value );
OBJ. Options [obj. Options. Length] = O;
If (selected ){
O. Selected = true;
}
}
// Delete the specified value
// Value is the deleted Value.
Function removeoptionbyvalue (OBJ, value ){
For (I = obj. Options. Length-1; I> = 0; I --){
If (obj. Options [I]. value = value ){
OBJ. Options [I] = NULL;
}
}
}
// Delete the specified index
// Index number deleted
Function removeoptionbyindex (OBJ, index ){
If (index> = 0 & index <obj. Options. Length ){
OBJ. Options [I] = NULL;
Return true;
}
Return false;
}
// Fill with Arrays
// Arr is an array. Each element is a small array of 2 characters, such as {"1", "Tianjin "}
// Selectedid selected sequence number
Function filloption (OBJ, arr, selectedid ){
If (ARR = NULL | arr. Length = 0 ){
Return;
}
For (I = 0; I <arr. length; I ++ ){
If (ARR [I]. Leng <2 ){
Continue;
}
Appendoption (OBJ, arr [I] [0], arr [I] [1], selectedid = I );
}
}
// Fill with Arrays
// Arr is an array. Each element is a small array of 2 characters, such as {"1", "Tianjin "}
// The selected value of the value
Function filloptionvalue (OBJ, arr, value ){
If (ARR = NULL | arr. Length = 0 ){
Return;
}
For (I = 0; I <arr. length; I ++ ){
If (ARR [I]. Leng <2 ){
Continue;
}
Appendoption (OBJ, arr [I] [0], arr [I] [1], arr [I] [0] = value );
}
}
// Select a value
Function selectoptionbyvalue (OBJ, value ){
For (I = 0; I <obj. Options. length; I ++ ){
If (obj. Options [I]. value = value ){
OBJ. Options [I]. Selected = true;
}
}
}