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()
$(document).ready(function(){
$('select').focus(function(){
$(this).attr("size",$(this).attr("expandto"));
var x = "select[tabindex='" + (parseInt($(this).attr('tabindex'),10) + 1) + "']";
$(x).fadeTo(50,0);
});
$('select').blur(function(){
$(this).attr("size",1);
var x = "select[tabindex='" + (parseInt($(this).attr('tabindex'),10) + 1) + "']";
$(x).fadeTo('fast',1.0);
});
});
Link for demo example
show selected option in dropdown javascript
This pure javascript solution would work for you. run and test
<html>
<head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Latest compiled JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></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>
<script>
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; window.open("/"+thetext); } })(i); } }
</script>
</html>
Is it possible to show all options from an HTML Select form field at once without clicking it?
http://jsfiddle.net/n1k5cLx0/
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.
HTML
<select size="3">
<option>Not Started</option>
<option selected>In Progess</option>
<option>Completed</option>
</select>
CSS
select{
overflow:auto;
}
Related Topics
Javascript Function Not Defined Error (But It Is Defined)
How to Automatic Click a Button on a Webpage
How to Insert Dashes Between Each Two Even Digits of a Specific Number
Filter/Search from the Drop-Down List of Options Using Angular
How to Delete Rows of Data Using Sequelize
How to Disable Dates Before Today in Jquery Datepicker
How to Change Size of Mat-Icon on Angular Material
Move Items in Ul Li Up and Down
How to Force Update Child Component from Parent Component in Reactjs
How to Merge Two Json Object Values by Id With Plain JavaScript (Es6)
Regex to Replace Everything Except Numbers and a Decimal Point
Wait for Http Request in Angular
Jquery Validation Code for Not Allowed Only Blank Space in Textbox
How to Download Pdf Automatically Using Js
How to Set Image to Fit Width of the Page Using Jspdf
How to Find Previous or Next Element from Array in JavaScript
Nosuchelementerror: Unable to Locate Element - Selenium Webdriver Using JavaScript