How to Use Js to Open an HTML Select to Show Its Option List

Is it possible to use JS to open an HTML select to show its option list?

Unfortunately there's a simple answer to this question, and it's "No"

How to open option list of HTML select tag on onfocus()

var x = "select[tabindex='" + (parseInt($(this).attr('tabindex'),10) + 1) + "']";
var x = "select[tabindex='" + (parseInt($(this).attr('tabindex'),10) + 1) + "']";

Link for demo example

show selected option in dropdown javascript

This pure javascript solution would work for you. run and test

<head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="">
<!-- jQuery library --> <script src=""></script>
<!-- Latest compiled JavaScript --> <script src=""></script></head>
<body> <nav> <div class="dropdown"> <button id="language" class="btn btn-warning dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" onclick="clickButton()"> English </button> <div id="languagelist" class="dropdown-menu" aria-labelledby="dropdownMenu2" onclick="clickItem(); return false"> <a class="dropdown-item" href="/en">English</a> <a class="dropdown-item" href="/fr">French</a> </div> </div> </nav></body>
function clickButton() { document.getElementById("languagelist").click(); }
function clickItem() { var element = document.getElementById("languagelist"); for (var i = 0; i < element.children.length; i++) { (function(index) { element.children[i].onclick = function() { var thetext = element.getElementsByTagName('a')[index].innerHTML; // var thehref = element.getElementsByTagName('a')[index].href; get the href here once you hosted, for testing I will use the name var buttonelement = document.getElementById("language"); buttonelement.innerText = thetext;"/"+thetext); } })(i); } }

Is it possible to show all options from an HTML Select form field at once without clicking it?

Are you looking for a list or do you still want a dropdown with the options shown as default. For a list style you could use the size attribute with the select element.


<select size="3">
<option>Not Started</option>
<option selected>In Progess</option>



Related Topics

Leave a reply