I am currently working on implementing a dropdown feature that will be triggered by a button within the search bar. The dropdown content is meant to be displayed underneath the search bar, however, I am facing some issues with my code.
<div class="col-8">
<div class="input-group mb-3">
<div class="input-group-prepend" id="button-addon3">
<div class="dropdown">
<button class="btn btn-outline-secondary " type="button" style="color:black;background-color: darkcyan">Search</button>
<div id="myDropdown" class="dropdown-content">
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</div>
</div>
<button class="btn btn-outline-secondary" type="button" style="color:black;background-color: darkcyan" onClick="myFunction()">Filter</button>
</div>
<input type="text" class="form-control" placeholder="Search Reports Here" aria-label="Example text with two button addons" aria-describedby="button-addon3">
</div>
</div>
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}