- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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>Advertisements