CopyCode The Code is as follows: <form name = "testform">
<Select name = "testselect">
<Option value = "first"> first option </option>
<Option value = "second"> second option </option>
<Option value = "third"> third option </option>
<Option> your browser can't handle this script </option>
</SELECT>
</Form>
Use the following code to access the options in the drop-down list:Copy codeThe Code is as follows: // get the option object
Document. Forms ['testform']. testselect. Options [I]
If you want to delete optionCopy codeThe Code is as follows: Document. Forms ['testform']. testselect. Options [I] = NULL;
If this option object is marked as null, this option is completely deleted from the list.
Note: This operation affects the number of options. Assume that you have deleted option [1] from the instance above, and the original option [2] element ('third option ') it will become the option [1] element (the option element goes top of the Order ).
Create a new option as follows:Copy codeThe Code is as follows: Document. Forms ['testform']. testselect. Options [I] = New Option ('new text', 'new value ');
On the page, you can see that the text and value displayed by option are the value attribute of this option.
When a form is submitted, the value is passed to the web server.
If you want to clear all options in the select box, as follows:Copy codeThe Code is as follows: Document. Forms ['testform']. testselect. Option. Length = 0;