) A piece of JS Code that operates the SELECT statement

Source: Internet
Author: User
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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.