Sub menu in option tag - html

The application I develop needs a submenu in the option tag. If a user clicks on one of the options from the submenu, it shows up in the search bar to be searched. However, I am not being able to do so.
This is the code:
<div class="form-row">
<select class="form-control mx-sm-3"">
<option selected="selected">Variant</option>
<option>Protein Variant</option>
<option>Copy Number Alterations</option>
<ul class="nav navbar-nav">
<li class="dropdown">
<option href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"> <span class="nav-label">Services</span> <span class="caret"></span></option>
<ul class="dropdown-menu">
<option>Service A</option>
<option>Service B</option>
<option>Service C</option>
</ul>
</li>
</ul>
</select>
</div>
Ideally, if the user hovers over 'service' there should be a new box with options 'Service A', 'Service B', 'Service C'

HTML way only offer optgroup
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
if you want a more specific dropdown, you need to implement it with javascript, like:
$(document).ready(function() {
$('.dropdown-submenu a').on("click", function(e) {
$(this).parents('ul').find('.dropdown-submenu ul').hide();
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
All South Africa
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li class="dropdown-submenu">
<a class="dropdown-item" href="#">Variant</a>
<a class="dropdown-item" href="#">Protein Variant</a>
<a class="dropdown-item" href="#">Copy Number Alterations</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Service A</a></li>
<li><a class="dropdown-item" href="#">Service B</a></li>
<li><a class="dropdown-item" href="#">Service C</a></li>
</ul>
</li>
</ul>
</div>

Related

My dropdown button in bootstrap doesn't work

I've tried all youtube videos, followed all the documentation of bootstrap. Please help me. I can't understand why it's not even working :(
Here's the basic HTML bootstrap code.
!DOCTYPE HTML>
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="scan-landing.component.css">
<link href="https://fonts.googleapis.com/css2?family=Jost:wght#500&display=swap"
rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-
alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-
alpha1/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
<div class="main">
<div class="scanner-shell" [hidden]="!hasDevices">
<select #selectedValue (change)="onDeviceSelectChange()">
<option [value]=" " [selected]="!currentDevice">No Device Selected</option>
<option *ngFor="let device of availableDevices" [value]="device.deviceId"
[selected]="currentDevice && device.deviceId === currentDevice.deviceId">{{device.label}}</option>
</select>
<zxing-scanner class="scanner-window" [(device)]="currentDevice" (scanSuccess)="onCodeResult($event)"
[formats]="formatsEnabled" (permissionResponse)="onHasPermission($event)"
(camerasFound)="onCamerasFound($event)"></zxing-scanner>
<!-- <section class="results" *ngIf="qrResultString">
<div>
<small>Result</small>
<strong>{{ qrResultString }}</strong>
</div>
<button (click)="clearResult()">×</button>
</section> -->
</div>
</div>
-->
It's so hard to troubleshoot since nothing shows in my console whenever I press it.
Your included bootstrap files were broken !
You should not split <link> or <script> into two lines.
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="scan-landing.component.css">
<link href="https://fonts.googleapis.com/css2?family=Jost:wght#500&display=swap"
rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
<div class="main">
<div class="scanner-shell" [hidden]="!hasDevices">
<select #selectedValue (change)="onDeviceSelectChange()">
<option [value]=" " [selected]="!currentDevice">No Device Selected</option>
<option *ngFor="let device of availableDevices" [value]="device.deviceId"
[selected]="currentDevice && device.deviceId === currentDevice.deviceId">{{device.label}}</option>
</select>
<zxing-scanner class="scanner-window" [(device)]="currentDevice" (scanSuccess)="onCodeResult($event)"
[formats]="formatsEnabled" (permissionResponse)="onHasPermission($event)"
(camerasFound)="onCamerasFound($event)"></zxing-scanner>
<!-- <section class="results" *ngIf="qrResultString">
<div>
<small>Result</small>
<strong>{{ qrResultString }}</strong>
</div>
<button (click)="clearResult()">×</button>
</section> -->
</div>
</div>

Dropdown with data toggle keeps two options selected

I have a dropdown menu with contains a data toggle for tabs. I have the problem that once I selected an item, the item stays selected and stays blue.
Any ways to fix this?
Code:
<ul class='nav nav-tabs'>
<li class='nav-item'>
<a class='nav-link active' data-toggle='tab' href='#overall'>Overall</a>
</li>
<li class='nav-item'>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Classes
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<button class="dropdown-item" data-toggle='tab' href="#zombie" type="button" aria-selected="true" >Zombie</button>
<button class="dropdown-item" data-toggle='tab' href="#spider" type="button"aria-selected="false">Spider</button>
<button class="dropdown-item" data-toggle='tab' href="#enderman" type="button"aria-selected="false">Enderman</button>
</div>
</div>
</li>
</ul>
<div class='tab-content'>
<div class='tab-pane container active' id='overall'>
blabla
</div>
<div class='tab-pane container' id='zombie'>
zombie
</div>
<div class='tab-pane container' id='spider'>
Spider
</div>
<div class='tab-pane container' id='enderman'>
Enderman
</div></div>
Make a id="dropdown-menu" next to class="dropdown-menu". This would be more convenient. reference line -20.
Make a Javascript that will add .active class in your clicked area/HTML. For example if you click on
<button class="dropdown-item" data-toggle='tab' href="#zombie" type="button" aria-selected="true" >Zombie</button>
that will add .active class in there
<button class="dropdown-item class" data-toggle='tab' href="#zombie" type="button" aria-selected="true" >Zombie</button>
And it will remove .active class from the previous position. This .active class is a Bootstrap class. It will render CSS style from Bootstrap.
Code below-
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.css"/>
<title>HTML5, CSS3 and JavaScript demo</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<ul class='nav nav-tabs'>
<li class='nav-item'>
<a class='nav-link active' data-toggle='tab' href='#overall'>Overall</a>
</li>
<li class='nav-item'>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Classes
</button>
<div id="dropdown-menu" class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<button class="dropdown-item" data-toggle='tab' href="#zombie" type="button" aria-selected="true" >Zombie</button>
<button class="dropdown-item" data-toggle='tab' href="#spider" type="button"aria-selected="false">Spider</button>
<button class="dropdown-item" data-toggle='tab' href="#enderman" type="button"aria-selected="false">Enderman</button>
</div>
</div>
</li>
</ul>
<div class='tab-content'>
<div class='tab-pane container active' id='overall'>
blabla
</div>
<div class='tab-pane container' id='zombie'>
zombie
</div>
<div class='tab-pane container' id='spider'>
Spider
</div>
<div class='tab-pane container' id='enderman'>
Enderman
</div></div>
<script>
var header = document.getElementById("dropdown-menu");
var btns = header.getElementsByClassName("dropdown-item");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function() {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
document.getElementById("overall").innerHTML = this.innerText;
});
}
</script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</body>
</html>

dropdown submenu in selection list

i have created a dropdown menu with provinces name and below each province its citesties are mentioned. I want these cities to appear in submenu on left side of province when it is clicked.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<select name="campus" id="campuslocation" class="browser-default" required="">
<optgroup label="Eastern Cape">
<option value="31">Umtata / Mthatha</option>
<option value="32">Willowmore</option>
<option value="33">Willowvale</option>
</optgroup>
<optgroup label="Free State">
<option value="47">Koppies</option>
<option value="48">Kroonstad</option>
</optgroup>
</select>
select is not the right element for this task, a dropdown is much better suited.
There is no default way to create submenus but it's easy enough to achieve.
$(document).ready(function() {
$('.dropdown-submenu a').on("click", function(e) {
$(this).parents('ul').find('.dropdown-submenu ul').hide();
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
All South Africa
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li class="dropdown-submenu">
<a class="dropdown-item" href="#">Eastern Cape</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Umtata / Mthatha</a></li>
<li><a class="dropdown-item" href="#">Willowmore</a></li>
<li><a class="dropdown-item" href="#">Willowvale</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a class="dropdown-item" href="#">Free State</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Koppies</a></li>
<li><a class="dropdown-item" href="#">Kroonstad</a></li>
</ul>
</li>
</ul>
</div>
Hope, this will help. We can able to use , instead of select.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
.dropdown {
width: 100px;
}
</style>
</head>
<body>
<div class="container">
<div class="dropdown">
<button class="btn btn-default btn-lg dropdown-toggle" type="button" data-toggle="dropdown">Select State
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li class="dropdown-submenu">
<a class="test" tabindex="-1" href="#">Eastern Cape <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Umtata / Mthatha</a></li>
<li><a tabindex="-1" href="#">Willowmore</a></li>
<li><a tabindex="-1" href="#">Willowvale</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a class="test" tabindex="-1" href="#">Free State <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Umtata / Mthatha</a></li>
<li><a tabindex="-1" href="#">Willowmore</a></li>
<li><a tabindex="-1" href="#">Willowvale</a></li>
</ul>
</li>
</ul>
</div>
</div>
<script>
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
</script>
</body>
</html>

How keep open mdl-menu with html select when it's click?

Here is an example of what is happening, when the dropdown list in the menu is clicked the menu is dismissed. Thanks in advance
#menu{
margin: 0 auto;
}
<link href="https://code.getmdl.io/1.3.0/material.light_blue-blue.min.css" rel="stylesheet"/>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<nav class="mdl-navigation">
<button id="menu" class="mdl-button mdl-js-button mdl-button--icon" style="background-color:blue">
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="menu" id="ul_container">
<p>DropDownList</p>
<li>
<select name="Select">
<option value="0">Option_0</option>
<option value="1">Option_1</option>
<option value="2">Option_2</option>
<option value="3">Option_3</option>
<option value="4">Option_4</option>
<option value="5">Option_5</option>
</select>
</li>
</ul>
</nav>
document.querySelector('.mdl-menu').addEventListener('click', function(event) {
event.stopPropagation();
});
document.querySelector('.mdl-menu').addEventListener('click', function(event) {
event.stopPropagation();
});
#menu{
margin: 0 auto;
}
<link href="https://code.getmdl.io/1.3.0/material.light_blue-blue.min.css" rel="stylesheet"/>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<nav class="mdl-navigation">
<button id="menu" class="mdl-button mdl-js-button mdl-button--icon" style="background-color:blue">
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="menu" id="ul_container">
<p>DropDownList</p>
<li>
<select name="Select">
<option value="0">Option_0</option>
<option value="1">Option_1</option>
<option value="2">Option_2</option>
<option value="3">Option_3</option>
<option value="4">Option_4</option>
<option value="5">Option_5</option>
</select>
</li>
</ul>
</nav>

Bootstrap 3 dropdown select value

I am trying to create a dropdown menu using select with a value/options. How can I do this using Bootstrap?
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="type" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Please Select
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="type">
<li>General User</li>
<li>Service Provider</li>
<li role="separator" class="divider"></li>
<li>Admin</li>
</ul>
</div>
For form components such as select bootstrap use .form-control, see docs here and see select docs example here
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<select class="form-control">
<option value="General User">General User</option>
<option value="Service Provider">Service Provider</option>
<option value="Admin">Admin</option>
</select>