"Implementing a Drop-Down Menu within a Text Field using Bootstrap

I'm looking to integrate a dropdown menu within my text input field with the help of Bootstrap:

<script type="text/javascript">
    $(document).ready(function(e) {
        $('.selectpicker').selectpicker();
        $('div.cow').scrollyou();
        $("select").selectBoxIt();
    });
</script>

<form action="#" method="post" class="form-inline">
    <div class="input-append">
        <input type="text" class="form-control input-lg" name="domain" size="40" value="Search"/>
        <select name="tld[]" class="selectpicker scrollMe" data-size="5" data-live-search="true" multiple data-selected-text-format="values" multiple title='Select Option' data-style="btn-primary" data-width="15%">
            <div class="cow">
                <option>One</option>
                <option>Two</option>
                <option>Three</option>
                <option>Four</option>
                <option>Five</option>
                <option>Six</option>
            </optgroup>
            </div>
        </select>
        <button class="btn btn-lg btn-inverse" type="submit" value="Search" />
            <i class="fa fa-search"></i>
        </button>
    </form>
</div>

Currently, I have incorporated Bootstrap-select and scrollYou into the setup.

Is there a way for me to nest my select field (including options) inside the search box itself?

Your assistance on this matter would be greatly appreciated!

Answer №1

This is the recommended method using Bootstrap:

Input Groups with Dropdowns

Here is an example incorporating a button on the right side:

<div class="input-group">
  <div class="input-group-btn">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
        Action 
        <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu">
      <li><a href="#">Action</a></li>
      <li><a href="#">Another action</a></li>
      <li><a href="#">Something else here</a></li>
      <li class="divider"></li>
      <li><a href="#">Separated link</a></li>
    </ul>
  </div><!-- /btn-group -->
  <input type="text" class="form-control">
  <span class="input-group-btn">
    <button class="btn btn-default" type="button">Go!</button>
  </span>
</div><!-- /input-group -->

If you are having issues with your current HTML, it is recommended to use the provided Bootstrap snippets for better compatibility and functionality.

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

What methods can be used to incorporate jQuery fadeIn and fadeOut into mouse event functions?

Currently, I am utilizing jQuery to switch images on mouse events (specifically hover), but I'm facing difficulty in implementing a smooth transition effect using fadeIn and fadeOut for the function below. var sourceIn = function () { ...

"The Jquery new Date function is returning inaccurate data when trying to pass it in the format yyyy dd

While utilizing remote desktop, I have come across the following code snippet in my JavaScript file: var birthday = new Date(2017, 1, 1); console.log(birthday); The output generated is as follows :- Wed Feb 01 2017 00:00:00 GMT+0000 (Coordinated Univ ...

Preventing scrolling in one div while focusing on another div

I am currently in the process of creating a website that functions as a single page site. The main feature of the site is a masonry grid of images. When a user clicks on an item, a detailed panel slides in from the left. Once the panel is closed, it slide ...

"Can you guide me on how to pick out one item before making my

Can someone please assist me with setting a default value for my input:hidden element before clicking on it? Here is the code I have: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> ...

"The art of communication: Websockets bridging the cross-domain

Currently, I am in the process of creating two web applications: The core application, developed using Java with Vert.x, is responsible for receiving data from various other apps and sending it to the client. The client application, built using PHP/JS, i ...

Establishing a default v-on event for a Vue component

Within my custom 'text-input' components, I include some default markup and an 'input' element. An effective method for passing the value of the 'text-input' to its parent is by emitting an event when the value changes. To h ...

What could be the reason behind CSS internal style not working while inline style is functioning properly?

Here is the code I am currently working with. It seems that there may be an issue, but I'm not sure what it could be. The first part contains internal CSS and below is inline CSS which appears to be functioning properly. My suspicion is that the image ...

Return to the previous page with different query parameters, not the same one

When it comes to reverting state location back by 1 step in Angular, we can utilize something along the lines of this.location.back();. This method works well unless the system redirects to the same URL but with different query parameters. In such cases, ...

PHP - Troubleshooting problems with file downloads

Having some frustrating issues with a website that I'm working on. Basically, the problem arises when a user fills out a form and jQuery then processes all the information to sendfile.php. The goal is for the user to automatically download a specific ...

display a dropdown menu with a default selection

Trying to pre-select a value in a dropdown from database but facing issues. Need assistance in resolving this problem. HTML <select class="form-control" ng-model="reportType.consolidationScopeId"> <option value="">Please select</option& ...

What is the best way to convert template interpolation using different words into a correct expression syntax in JavaScript regex?

I have a string that contains template interpolation along with words that are not inside the interpolation. The string can be in one of these various forms: foo{{bar}} {{foo}}bar foo{{bar}}baz {{foo}}{{bar}} foo {{foo}} {{foo}}bar{{baz}} The text interpo ...

The content is displayed below the navigation bar rather than beside it

I'm having an issue with the layout of my webpage. The new content I add appears below the navbar on the left side of the page instead of beside it. Can someone help me troubleshoot this problem? Below, you'll find the relevant HTML and CSS code ...

Rotate the mat-select arrow when the dropdown opens (moving in both upward and downward directions)

Currently, I have a mat-select dropdown icon arrow that toggles facing up or down based on user clicks. However, after selecting an option and closing the dropdown, the arrow remains in the upward position unless further clicked and held. I have attempted ...

Dynamic content displayed within adjacent div elements

I am currently working on a project where I am dynamically generating an outline by creating panels and labels in ASP.NET. Each node in the outline is defined by an outline number and outline text, which are obtained from a database that defines the relati ...

Arranging DIV elements with flexbox and CSS

I have a straightforward layout featuring a 3-column design that consists of a back button, a main content section, and a forward button: <div class="container h100"> <div class="row align-items-center h100"> ...

Leveraging a VueJS prop as a variable in an array mapping operation

Trying to figure out a solution where a variable (prop) can be used in an array map function. The initial code snippet looks like this: var result = this.$store.getters['example/store'].map(a => a.fixed_column) I aim for fixed_column to be ...

Is it possible to populate the blank cells in the weekday columns for previous and following months in a mat-datepicker or mat-calendar's display?

In order to enhance user experience, I am designing a calendar that allows users to select dates. My goal is to populate the empty cells at the beginning of the first week with dates from the previous and next months. For this project, I am utilizing the ...

Npm is unable to locate the package.json file in the incorrect directory

Hello, I am currently in the process of setting up webpack. I have all the configurations ready, but when I attempt to execute webpack in my terminal, it looks for the package.json file in the incorrect location. Is there a way for me to modify the path ...

How can I tally the frequency of characters in a given string using Javascript and output them as numerical values?

I am in the process of tallying the frequency of each individual character within a given string and representing them as numbers. For example, let's consider the string "HelloWorld". HELLOWORLD There is one H - so 1 should be displayed with H remov ...

The transitions on my jQuery Mobile page are not functioning correctly

I am currently working on a custom MVC structure using Handlebars and jQuery Mobile. To manually manage routing, I have disabled two jQM parameters: $.mobile.linkBindingEnabled = false; $.mobile.hashListeningEnabled = false; These lines disable link bind ...