Add:
JS Code
1. Function selectchange ()
2 .{
3. var sel = Document. getelementbyid ("select1 ");
4. Option option = New Option ("text", "value ");
5. Sel. Add (option );
6 .}
Function selectchange ()
{
VaR sel = Document. getelementbyid ("select1 ");
Option option = New Option ("text", "value ");
Sel. Add (option );
}
Delete all:
JS Code
1.doc ument. getelementbyid ("select1"). Options. Length = 0;
Document. getelementbyid ("select1"). Options. Length = 0; delete a single option element:
JS Code
1. var sel = Document. getelementbyid ("select1 ");
2. For (I = 0; I <SEL. Options. length; I ++)
3 .{
4. If (SEL. Options [I]. Selected)
5 .{
6. Sel. Options [I] = NULL; // if it is set to null, this element is deleted.
7 .}
8 .}
VaR sel = Document. getelementbyid ("select1 ");
For (I = 0; I <SEL. Options. length; I ++)
{
If (SEL. Options [I]. Selected)
{
Sel. Options [I] = NULL; // if it is set to null, this element is deleted.
}
} Value:
JS Code
1. var sel = Document. getelementbyid ("select1 "):
2. var val = SEL. Options [SEL. selectedindex]. Value // You can also write var val = SEL. value;
3. Alert (VAL); // obtain the value of Option
4. var TXT = SEL. Options [SEL. selectedindex]. Text
5. Alert (txt); // obtain the option text (text)