Use the following code to access the options in the drop-down box:
// Get option object
document.forms['testform'].testselect.options[i]
If you want to delete option
document.forms['testform'].testselect.options[i] = null;
Mark this option object as null, and this option will be completely removed from the list.
Note: This operation will affect the number of options. Assume that in the above example, you delete option[1], the original option[2] element ('Third option') will become the option[1] element (option elements are pushed up in order).
Create a new option as follows:
document .forms['testform'].testselect.options[i] = new Option('new text','new value');
The user sees the text and value displayed by the option on the page The value is the VALUE attribute of this option.
When the form is submitted, the VALUE value is passed to the WEB server.
If you want to clear all options in the select box, as follows:
document.forms['testform'].testselect.option.length = 0;
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn