
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to show all the options from a dropdown list with JavaScript?
To show all the options from a dropdown list, use the options property. The property allows you to get all the options with length property.
Example
You can try to run the following code to get all the options from a drop-down list.
<!DOCTYPE html> <html> <body> <form id="myForm"> <select id="selectNow"> <option>One</option> <option>Two</option> <option>Three</option> </select> <input type="button" onclick="display()" value="Click"> </form> <p>Click the button to get all the options</p> <script> function display() { var a, i, options; a = document.getElementById("selectNow"); options = ""; for (i = 0; i < a.length; i++) { options = options + "<br> " + a.options[i].text; } document.write("DropDown Options: "+options); } </script> </body> </html>
- Related Articles
- How to remove options from a dropdown list with JavaScript?
- How to select multiple options in a dropdown list with JavaScript?
- How to get the number of options in the dropdown list with JavaScript?
- How to show the index of the selected option in a dropdown list with JavaScript?
- How to get all the options in the dropdown in Selenium?
- How will you get all the options in a static dropdown?
- How to display the selected option in a dropdown list with JavaScript?
- How to get all options of a dropdown using Python Selenium webdriver?
- How to Create a Dropdown List with Array Values using JavaScript
- How to create a dropdown list using JavaScript?
- How to get the id of a form containing a dropdown list with JavaScript?
- JavaScript get the length of select options(dropdown)?
- How to select an item from a dropdown list using Selenium WebDriver with java?
- Highlighting Dropdown Options in ReactJS
- How to create a clickable dropdown menu with CSS and JavaScript?

Advertisements