What are some ways to style a DropDownList?

I'm looking to style the dropdownlist to display two field columns similar to the image shown. Is it possible to achieve this using HTML5 datalist or jquery?

Answer №1

If you're looking to customize the style of a Combobox, consider using the IgniteUI library for easy control. Check out this demo I put together here

Here's how you can set it up:

<div id="combo"></div>

And here's the corresponding JavaScript code:

$(function () {

    var data = [{
        "ID": 1,
            "Name": "John Smith",
            "Age": 45
    }, {
        "ID": 2,
            "Name": "Mary Johnson",
            "Age": 32
    }, {
        "ID": 3,
            "Name": "Bob Ferguson",
            "Age": 27
    }];

    $("#combo").igCombo({
        dataSource: data, // JSON Array defined above         
        valueKey: "ID",
        textKey: "Name",
        width: "360px",
        itemTemplate: "<div class='comboItemContainer'><div class='colOne'>${Name}</div><div class='colTwo'>${Age}</div></div>"
    });

});

Finally, here's some CSS to style your Combobox:

.comboItemContainer {
    width: auto;
    font-family: "Courier New", Courier, monospace;
}
.colOne {
    border-right: 1px dashed gray;
    float: left;
    width: 300px;
}
.colTwo {
    float: left;
    padding-left: 5px;
}

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 is the process for transferring a file to a server from a PhoneGap or web application using FTP?

Can a PhoneGap application establish a connection with a server and transfer files using FTP? In simpler terms, is it feasible to initiate an FTP connection using Ajax or jQuery? ...

Converting dates from JavaScript to Central Daylight Time (CDT) using the new

I have a function below that is used to format a date from an API Response. However, when the date "2021-10-02" is received in the response, the new Date() function converts it to Mon Oct 01 2021 19:00:00 GMT-0500 (Central Daylight Time), which is one da ...

Find your way to a unique div created through a while loop

Describing my issue clearly, I am using PHP to retrieve data from MySQL. The table contains multiple records. To display table records, I have implemented a while loop with mysqli_fetch_array() as the condition. These records need to be echoed out (in HT ...

Ways to resolve the issue with TypeError: CSS2Properties lacking an index property setter for '0'

I'm currently working on application development using ReactJs and Material UI. When I try to open the application in Mozilla Firefox, an error message pops up saying "TypeError: CSS2Properties doesn't have an indexed property setter for ' ...

Default Documents on Login.aspx are being displayed even though it hasn't been specified in the web.config file

When I decided to move my website from the built-in web server (Cassini) to IIS, I encountered an issue with my Login.aspx page. The web.config file was showing an error "The requested page cannot be accessed because the related configuration data for the ...

The functionality of AJAX is successful when tested on a local server, but encounters issues when deployed on a live

While the following code functions correctly on localhost, it fails to work on the live server. IMPORTANT UPDATE: There's only 1 issue remaining: Upon successful execution of this AJAX block: $(".FixedDiv").addClass("panel-danger"); setTimeout(c ...

What sets apart local and global variables when it comes to JavaScript?

It has come to my attention that in the realm of JavaScript, there are instances where a variable is created within a function without explicitly declaring it with var. For instance: function myfunction() { x = 10; var y = 10; } What sets these ...

Refresh div content dynamically with anchor tag in place

I have a dilemma with the following div that contains an anchor tag linking to a php script responsible for updating information in a database and returning to this page. My goal is to execute this php script by clicking on the anchor tag, update the datab ...

Styling a dynamically-injected div using an AJAX request (xhrGet)

Hello everyone, currently I am using the code below to fetch updated content after receiving a "push" event from a server. The new content is then used to replace the existing div/content. However, I'm facing an issue where none of my styles from the ...

What is the best way to trigger a JavaScript alert from a static method in Asp.net server-side code?

I am struggling to have a JavaScript alert work in a static method for server-side code in ASP.NET using C#. I've attempted multiple approaches, but nothing seems to be effective. One example is as follows [WebMethod] public static void EntrySave(st ...

"Encountering an error with Meteor while attempting to generate ObjectID due to an invalid hexadecimal

Recently, I've been working on updating data in the database while also inserting new information using jQuery (I know, I'm still learning). After this process, I need to be able to click on the data and display some user interface elements, whic ...

Why does the selected attribute not function properly in <select><option> when used with ngModel?

I encountered an issue with Angular 6: when using a component based on the <select> element (combo-box), everything works fine if I use it in the traditional way, where I specify the selected attribute. In this case, the default option appears select ...

Display a button beneath a targeted textarea after clicking

Lately, I've been diving into jQuery and trying to learn more about it. My main goal is to make it so that when a user clicks on an "Edit" button, the note next to that particular button will transform from a div to a textarea. The issue I'm ru ...

The issue with Django where HTML links are pointing to an incorrect directory for the CSS files

On my main page, the URL localhost:8000/helloworld/greeter can be found at helloworld\templates\hello: <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Hello!</title> ...

Validating Django formsets using axios

Update 2: After struggling with axios, I decided to switch to using ajax with some code from <script> $(document).ready(function () { $("#feedbackform").submit(function (event) { event.preventDefault(); $.ajax({ ...

Dynamic value changes in AngularJS checkboxes controlled by ng-model within controller

I have a page that loads data from a database and displays it in a grid. It has a button to manually refresh the data, as well as a checkbox for automatic refreshing. Below is the HTML code: <div id="TestViewTable" ng-controller="testTableManager" ng- ...

Can a stack method be utilized to create a HTML tag checker?

I've been developing a project to create an HTML validation tool based on stacks, but I've encountered some issues. The main objective is to verify if the HTML tags are correctly nested and closed. However, there seem to be discrepancies in the r ...

The DIV element fails to encompass all of its content

There seems to be an issue with the only div element on my page. It's covering the middle of the page, but I managed to make it extend all the way down using CSS tweaks. However, there is a problem - the video inside the div is overflowing: Below is ...

Raise the image above the wrapping div, positioning it at the very bottom

I'm struggling to position an image within a div in a way where: it protrudes above the div it begins at the very bottom of the div (with a small gap that I can't eliminate) Below is the relevant HTML code snippet: <div class="teaser-imag ...

Tips for arranging cards in columns without causing vertical scrolling to be triggered

I am working with Bootstrap 5 and have created a column with multiple cards: https://jsfiddle.net/fzxc1v69/ Currently, all the cards are displayed one below the other, but I want them to be lined up horizontally instead. In my code, the .section class i ...