Creating a multi-tiered cascading menu in a web form: Harnessing the power of

In my form, there is a field called 'Protein Change' that includes a multi-level dropdown. Currently, when a user selects an option from the dropdown (for example, CNV->Deletion), the selection should be shown in the field. However, this functionality is not working as expected.

I have implemented Bootstrap and JavaScript for this task. Can I utilize the onclickevent() function to trigger the necessary action upon clicking and displaying the corresponding data?

 $(".btn-group, .dropdown").hover(
        function () {
            $('>.dropdown-menu', this).stop(true, true).fadeIn("fast");
            $(this).addClass('open');
        },
        function () {
            $('>.dropdown-menu', this).stop(true, true).fadeOut("fast");
            $(this).removeClass('open');
        });
.dropdown-submenu {
            position: relative;
        }

        .dropdown-submenu > a:after {
            content: ">";
            float: right;
        }

        .dropdown-submenu > .dropdown-menu {
            top: 0;
            left: 100%;
            margin-top: 0px;
            margin-left: 0px;
        }

        .dropdown-submenu:hover > .dropdown-menu {
            display: block;
        }
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<script language="JavaScript" src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>

<link href="css/dialog.css" rel="stylesheet" media="screen" />
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>

<body>
<div class="container-fluid" style="padding-left: 20px;">
    <form class="form-inline">
        <fieldset disabled>
            <div class="form-row">
                <select class="fields inputstl form-control form-control col-md-12" onchange="changevar(this,event);">
                    <option selected="selected">TumorType</option>
                </select>
            </div>
        </fieldset>

        <div class="form-row">
            <select id="selecttumor" required class="values inputstl form-control mx-sm-3" value="Bladder Urothelial Carcinoma" type="search" style="width: 200px;">
                <option value="4">Bladder Urothelial Carcinoma</option>
                <option value="5">Breast invasive carcinoma</option>
                <option value="6">Colon adenocarcinoma and Rectum adenocarcinoma</option>
            </select>
        </div>
        <fieldset disabled>
            <div class="form-row">
                <select class="fields inputstl form-control form-control col-md-12" onchange="changevar(this,event);">
                    <option selected="selected">Gene</option>
                </select>
            </div>
        </fieldset>

        <div class="form-row">
            <input id="selectGene" value="AGXT" onfocus="addSysnomousInput(this,event);" required class="values inputstl form-control mx-sm-3" type="search">
            <span id="selectGene" class="form-control-clear glyphicon glyphicon-remove form-control-feedback hidden"></span>
        </div>

        <div class="form-row">
            <div class="col-lg-12">
                <div class="btn-group">
                    <a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-outline-secondary dropdown-toggle"
                       href="">
                        Protien Search
                    </a>
                    <ul class="selectPkeyVkey dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
                        <li value ="1"><a class="dropdown-item">Protein Search</a></li>
                        <li value="2"><a class="dropdown-item">Nucleotide Search</a></li>
                        <li><a class="dropdown-item">Group Variants</a></li>
                        <li class="dropdown-divider"></li>
                        <li class="dropdown-submenu">
                            <a class="dropdown-item" tabindex="-1" href="#">
                                CNV
                            </a>
                            <ul class="dropdown-menu">
                                <li value="3"><a class="dropdown-item" tabindex="-1">Copy Number Gain</a></li>
                                <li value="3"><a class="dropdown-item">Copy Number Loss</a></li>
                                <li value ="3"><a class="dropdown-item">Deletion</a></li>
                                <li value ="3"><a class="dropdown-item">Diplotype</a></li>
                                <li value ="3"><a class="dropdown-item">Distinct Chromosome</a></li>
                                <li value ="3"><a class="dropdown-item">Duplication</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <fieldset disabled>
            <div class="form-row">
                <select class="fields inputstl form-control form-control col-md-12" onchange="changevar(this,event);" style="margin:15px;">
                    <option selected="selected">Variant</option>
                </select>
            </div>
        </fieldset>
        <div class="form-row" style="margin: 10px">
            <input id="selectVarinput" value="Gly170Arg" onfocus="addSysnomousInput(this,event);" required class="form-control mx-sm-3" type="search">
            <span id="selectVarinput" class="form-control-clear glyphicon glyphicon-remove form-control-feedback hidden"></span>
        </div>


        <button id="searchButton" class="searchclass btn btn-primary mx-sm-3" onclick="collectLogic(this,event);return false;">Search</button>
    </form>
</div>


</body>
</html>

Answer №1

The drop-down menu is not functioning like a select element, so you will need to manually update the text of #dLabel.

Using jQuery, you can achieve this with the following code:

$(".dropdown-item").click(function() {
  let newText = $(this).text();
  $("#dLabel").text(newText);
});

For a complete example, check out https://jsfiddle.net/9q4xa15c/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving a function from a JavaScript file located in a publicly accessible directory

Having trouble accessing a function from the JS file scripts.js within the public folder where my CSS file is also located. Despite following various tutorials like this, I keep encountering the error message Error: Cannot find module './scripts.js&ap ...

Utilize Material icons in CSS for a list in Angular 9

My task involves altering the HTML provided by a content management system for one of our applications. Specifically, I need to replace all "ul"s with <mat-icon>check_circle_outline</mat-icon> instead of the default "." The challenge lies in t ...

The mat-table's data source is failing to refresh and display the latest

When I click on a column header to sort the table, a function should trigger and update the data. However, the data is not updating as expected. Below is the code for the function and the table: <table mat-table #table [dataSource]="dataSourceMD&qu ...

Angular Material's md-checkbox is a required component

I am working on a form that consists of checkboxes representing the days of the week. When the user hits submit without selecting any checkboxes, I want an error message to appear. Here is the HTML code snippet that I have: <form id="addEditForm" nam ...

Top method for filling an array with strings

Imagine having an array called 'newArray'. var newArray = []; You can add strings to it like this: var thisString = 'watch'; newArray.push(thisString); Now, if you want to have 50 instances of the 'thisString' in the newAr ...

What is the functionality of require(../) in node.js?

When encountering var foo=require(../), what specific modules does node.js search for? It may appear to look in the directory above the current one, but what exactly is it seeking and how does it function? Is there a comparison with include in C or impor ...

Drift above a pair of elements

Explaining my issue is a bit complex, so I'll provide an example: I aim to place a floated element (the blue box) over two other elements (red and green), all within a fixed-width and centered layout (achieved by the black border box). Additionally, ...

The issue of receiving an undefined JSON response persists in an AJAX file upload scenario

Currently, I am utilizing Valum's Ajax File uploader for handling same-page file uploads. The issue I'm facing is that despite numerous attempts and variations in my script, I consistently receive "undefined" when trying to access responseJSON[&a ...

What Makes Sports Illustrated's Gallery Pages Load So Quickly?

After thoroughly examining their code, I'm still puzzled. Are they loading complete new pages, or are they utilizing jQuery to modify the browser's URL while keeping most of the page unchanged? I'm currently inspecting the source of this pa ...

Rotating an object with the mouse in three.js without relying on the camera movements

I am working on a project where I need to create multiple objects and rotate each of them individually using the mouse. While I have been able to select an object with the mouse, I am facing challenges when it comes to rotating them with the mouse. Cur ...

Accepting PHP multidimensional array through ajax

My PHP code includes a script to open a database, fetch data, and encode it into JSON format. include_once($preUrl . "openDatabase.php"); $sql = 'SELECT * FROM dish'; $query = mysqli_query($con,$sql); $nRows = mysqli_num_rows($query); if($nRow ...

Displaying radio values in an Angular ng-repeat directive

I am new to Angular and facing difficulties in capturing the selected radio value when using ng-repeat. The documentation is a bit unclear on this matter. Any assistance or guidance would be highly appreciated. <div ng-repeat="item in ed"> <lab ...

What is the process for incorporating a new task into my HTML/CSS/JavaScript to-do list application when the Enter key is pressed?

Currently, I am working on developing a to-do list application using HTML, CSS, and JavaScript. The application includes a text input field for users to enter their tasks, along with an "Add Task" button. However, I want to enhance the user experience by a ...

Converting Selenium Webdriver Xpath value to CSS: A Step-by-Step

We are looking to transform the lengthy HTML Xpath values in the existing code into a shorter CSS value: driver.findElement(By.cssSelector(".form button")).click(); ...

Using AngularJS to Send Elements to Scripts and Selectors

When I use the following template: <div id="container"> <textarea name="message"></textarea> <button value="send" ng-click="testMethod($parent)"> </div> In the JavaScript code: $scope.testMethod = function(element) ...

Retrieve information from Wikipedia corresponding to the keyword entered in the form

Imagine a situation in which a user inputs a keyword into a text field. I am seeking a way to retrieve relevant data from Wikipedia that corresponds to the entered keyword. How can this be accomplished? <form method=POST action=someaction> ...

Tips for utilizing Material UI's Tooltip feature alongside a TableRow

I'm currently facing an issue where I'm trying to include a MUI TableRow inside a Tooltip component in order to display a long uuid when hovering over the row. However, I noticed that all the columns of the row are being compressed into the first ...

Async/await is restricted when utilizing serverActions within the Client component in next.js

Attempting to implement an infinite scroll feature in next.js, I am working on invoking my serverAction to load more data by using async/await to handle the API call and retrieve the response. Encountering an issue: "async/await is not yet supported ...

Having trouble changing the Font Awesome icon on click?

I'm struggling to figure out why I can't change a font awesome icon using a toggle. I've tried various solutions but nothing seems to be working. Any insights on what might be causing this issue? (HTML) <span class="toggle-icon" ...

Invoke the function for every element during the mapping process

I am attempting to call a function in React Native maps for each element. This function will randomly determine properties of the rendered component, making sure that each component is unique. The renderComponent function takes an argument called item as w ...