Ways to assign a placeholder to a dropdown menu

I'm trying to add a text placeholder to my selectbox, but all the options disappear when I try to do so. Can someone help me with this issue?

Here is the code snippet I'm using:

window.onload = function () {
   $('#slide').editableSelect({ effects: 'slide' });
   $('#html').editableSelect();

   $('#onselect').editableSelect({
       onSelect: function (element) {
           $('#afterSelect').html($(this).val());
       }
   });
}
input.es-input {
  padding-left:20px!important;
  direction:rtl;
  background-color:#FFF !important;
  border:1px solid #ccc !important;
  height:40px !important;cursor:pointer;
  background-position:5% !important;
background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAICAYAAADJEc7MAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAG2YAABzjgAA4DIAAIM2AAB5CAAAxgwAADT6AAAgbL5TJ5gAAABGSURBVHjaYvz//z8DOYCJgUzA0tnZidPK8vJyRpw24pLEpwnuVHRFhDQxMDAwMPz//x+OOzo6/iPz8WFGuocqAAAA//8DAD/sORHYg7kaAAAAAElFTkSuQmCC) left center no-repeat
}

.es-list {
  position:absolute;
  padding:0;
  margin:0;
  border:1px solid #d1d1d1;
  display:none;
  z-index:1000;
  background:#fff;
  max-height:160px;
  overflow-y:auto;-moz-box-shadow:0 2px 3px #ccc;-webkit-box-shadow:0 2px 3px #ccc;
  box-shadow:0 2px 3px #ccc
}

.es-list li{
  display:block;
  height:45px;
  padding:0 !important;
  margin:0 !important;
  width:100%;
}

.es-list li.selected {
  background:#2476bb;color:#fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://www.jqueryscript.net/demo/jQuery-Plugin-For-Custom-Filterable-Select-Box-Editable-Select/source/jquery.editable-select.js"></script>
<html>
<head>
</head>
<body>
<select id="slide">
   <option  selected="true" disabled>one</option>
 <option>one</option>
<option>two</option>
  <option>three</option>
</select>
</body>
</html>

Answer №1

The function of this element is not a select box but a type head. In the DOM, there is an input box labeled slide. You can insert a placeholder into input#slide.

Feel free to test out this code:

$(document).ready(function(){
  $('#slide').attr("placeholder", "One");
})

window.onload = function () {
   $('#slide').editableSelect({ effects: 'slide' });
   $('#html').editableSelect();

   $('#onselect').editableSelect({
       onSelect: function (element) {
           $('#afterSelect').html($(this).val());
       }
   });
}

$(document).ready(function(){
  $('#slide').attr("placeholder", "One");
})
input.es-input {
  padding-left:20px!important;
  direction:rtl;
  background-color:#FFF !important;
  border:1px solid #ccc !important;
  height:40px !important;cursor:pointer;
  background-position:5% !important;
background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAICAYAAADJEc7MAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAG2YAABzjgAA4DIAAIM2AAB5CAAAxgwAADT6AAAgbL5TJ5gAAABGSURBVHjaYvz//z8DOYCJgUzA0tnZidPK8vJyRpw24pLEpwnuVHRFhDQxMDAwMPz//x+OOzo6/iPz8WFGuocqAAAA//8DAD/sORHYg7kaAAAAAElFTkSuQmCC) left center no-repeat
}

.es-list {
  position:absolute;
  padding:0;
  margin:0;
  border:1px solid #d1d1d1;
  display:none;
  z-index:1000;
  background:#fff;
  max-height:160px;
  overflow-y:auto;-moz-box-shadow:0 2px 3px #ccc;-webkit-box-shadow:0 2px 3px #ccc;
  box-shadow:0 2px 3px #ccc
}

.es-list li{
  display:block;
  height:45px;
  padding:0 !important;
  margin:0 !important;
  width:100%;
}

.es-list li.selected {
  background:#2476bb;color:#fff;
}
<select id="slide">
    <option>one</option>
    <option>two</option>
    <option>three</option>
  </select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script src="http://www.jqueryscript.net/demo/jQuery-Plugin-For-Custom-Filterable-Select-Box-Editable-Select/source/jquery.editable-select.js"></script>

Answer №2

If I'm following your intention correctly, you may want to consider implementing the following code:

Make sure to pay attention to the selected and disabled attributes on the initial option.

<select id="slide">
  <option disabled selected hidden>Please Select</option>
  <option>one</option>
  <option>two</option>
  <option>three</option>
</select>

Answer №3

An easy solution is to simply include a 'placeholder' attribute within the 'select' tag

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

Hover over to see the impressive special effect produced by Scriptaculous Effect.Appear

Having an issue with using scriptaculous Effect.Appear() as a menu option. I'm trying to create a flash-like menu using pure css and scriptaculous. I've managed to achieve the desired outcome where hovering over a box triggers a text (with displ ...

Promise rejection caused by SyntaxError: Unexpected token i found in JSON at position 0 while trying to fetch a raw file from Gitlab

I'm attempting to retrieve a raw file from a Gitlab repository by following the official documentation. Here are the functions in question: methods: { async getProjects(url, method, payload) { const token = this.$store.getters.token ...

The AJAX call is successfully returning the expected response, however, the HTML content is not being

https://i.sstatic.net/8Loq1.pngI've been working on a project where I need to position some HTML elements based on the response I get. However, I've encountered an issue where even though the response is returned, nothing is changing on the page. ...

Sorting feature fails to function properly when used in combination with pagination and

<table> <thead> <tr> <th class="col-md-3" ng-click="sortDirection = !sortDirection">Creation Date</th> </tr> </thead> <tbody> <tr dir-paginate="item in items | filter:itemFilter | items ...

The functions getFiles and getFolders will consistently retrieve a single file or folder each time they are

When attempting to fetch all files and folders from my Google Drive, the function .getFiles() is only returning one file, while .getFolders() is only returning a single folder. However, I can confirm that there are multiple folders and files in my drive. ...

ng-repeat is not functioning properly despite the presence of data

Currently, I am in the process of building a basic Website using the MEAN stack, but I'm facing an issue with an ng-repeat that is failing to display any content. Oddly enough, when I attempt something similar in another project, it works perfectly fi ...

Changing a string into a date format with the help of JavaScript AngularJS

My string is as follows: 13-12-2017 05:05 AM I am looking to convert it to the following format: Date 2017-12-13T05:05:00.000Z Attempted Solution: var mydate = '13-12-2017 05:05 AM'; var selectedDate = new Date(mydate); Upon logging the selec ...

SMMRY API bug stemming from a lack of necessary variables

Here is the code snippet: // Article Summary var params = { host: 'api.smmry.com', path: '/', body: { SM_API_KEY: 'B...', SM_URL: 'www.bbc.com/sampleNews' } }; http.get(params, functi ...

Customize the printing settings within bootstrap by modifying the background color from transparent to a solid color using CSS/SCSS

I am facing an issue with the bootstrap CSS/print feature. In the bootstrap CSS (reset.css) file, all styles are cleared for printing purposes. @media print { * { text-shadow: none !important; color: black !important; background: transparen ...

Reasoning behind splitting this solution into a function utilizing Javascript

Today, while working on a coderbyte problem, I managed to solve it on my own without any outside help, and it felt fantastic. However, upon completion, I realized that I solved it without creating any functions. Rather, I kept referring back to a previous ...

Creating mock objects for unit testing is a valuable skill to have in your coding

What is the best approach for writing test cases as a beginner? I need guidance on how to write test cases effectively. Exploring Angular functions and classes. picklistScroll() { const picklistWrapper = document.getElementsByClassName('pic ...

Database query retrieval unsuccessful when using jQuery Ajax to populate form fields

I have a form that dynamically populates select fields with data based on previous selections. It works flawlessly on my Localhost/Xampp setup with PHP8. However, when I try to run it on my server, it only seems to work "once" per category. In essence, he ...

Experimenting with mocha and Nightmare.js, utilizing traditional syntax and without the use of ES6 features

Here is a real-world example that I am using: How to Use Nightmare.js without ES6 Syntax and Yield However, when I include it in a Mocha test, it times out. Here's the code snippet: describe('Google', function() { it('should perform ...

Eradicating Pinpointers on Navigation Tool (Google Maps)

I have a feature that utilizes an ajax request to generate a marker or multiple markers when the user interacts with the map. Once a marker is created at a specific location by the user, I then set up a click event on the marker itself. The issue arises w ...

Is there a way to combine fixed and dynamic size elements within a flexbox container?

Currently, I am working on creating a layout that combines the automatic sizing feature of flexbox with fixed-size elements: <View style={{ height: 70, alignItems: "center" }}> <Text style={{ flex: 1, textAlign: "right", paddingRight: 10 }}&g ...

What is the method for configuring body attributes in CSS with AngularJS?

Setting the background image of a page using CSS: body { background: url(http://momentumbooks.com.au/wp-content/uploads/2013/06/space.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-backg ...

Convert an array to UTF-8 encoding and extract the values into a text input field

Having encountered a minor issue, I've successfully moved data from one file to another using Ajax with the help of echo in my query. However, I'm now attempting to utilize json_encode(); and facing some difficulties. Could someone please point o ...

Guidelines for iterating through a nested JSON array and extracting a search query in Angular

I'm currently working with a complex nested JSON Array and I need to filter it (based on the name property) according to what the user enters in an input tag, displaying the results as an autocomplete. I've started developing a basic version of t ...

Error: The function $(...).froalaEditor is not recognized | This issue is occurring within the $(document).ready(function(){}) block in J

When attempting to set HTML content of the Froala editor within a JSP using $(document).ready(), this error occurs. TypeError: $(...).froalaEditor is not a function | $(document).ready(function(){}) in JSP I read on a GitHub issue that placing jQuery sc ...

React Native - Issue with array value not reflecting in Text component

import React, {useState} from 'react'; import { FlatList, Text, View} from 'react-native'; import {styles, styleBox} from './components/styles'; import Slider from '@react-native-community/slider'; export default fu ...