2-Column Type-Ahead Dropdown in HTML

Hello Experts,

Can anyone tell me how can I have a 2-Column Type-Ahead Dropdown in HTML, sort of the one that I am attaching here?

Thia is from MS Access, but as you will see it has type-ahead feature and 2-columns. I cannot use the optgroup because the groups are very long and the user is complaining that they cannot keep track.

Any feed back will be greatly appreciated.

Thank you
2-Column-Type-Ahead-Dropdown.jpg
APD TorontoSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
There are more than one option for this.  But the key is simply to format the output.  One option is using jquery ui https://jqueryui.com/autocomplete/#custom-data or http://jsfiddle.net/alforno/g4stL/  and there is also typeahead.js where you can create your custom templates https://twitter.github.io/typeahead.js/examples/#custom-templates

Using jquery ui, you can see their sample uses li's
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Custom data and display</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #project-label {
    display: block;
    font-weight: bold;
    margin-bottom: 1em;
  }
  #project-icon {
    float: left;
    height: 32px;
    width: 32px;
  }
  #project-description {
    margin: 0;
    padding: 0;
  }
  </style>
  <script>
  $(function() {
    var projects = [
      {
        value: "jquery",
        label: "jQuery",
        desc: "the write less, do more, JavaScript library",
        icon: "jquery_32x32.png"
      },
      {
        value: "jquery-ui",
        label: "jQuery UI",
        desc: "the official user interface library for jQuery",
        icon: "jqueryui_32x32.png"
      },
      {
        value: "sizzlejs",
        label: "Sizzle JS",
        desc: "a pure-JavaScript CSS selector engine",
        icon: "sizzlejs_32x32.png"
      }
    ];
 
    $( "#project" ).autocomplete({
      minLength: 0,
      source: projects,
      focus: function( event, ui ) {
        $( "#project" ).val( ui.item.label );
        return false;
      },
      select: function( event, ui ) {
        $( "#project" ).val( ui.item.label );
        $( "#project-id" ).val( ui.item.value );
        $( "#project-description" ).html( ui.item.desc );
        $( "#project-icon" ).attr( "src", "images/" + ui.item.icon );
 
        return false;
      }
    })
    .autocomplete( "instance" )._renderItem = function( ul, item ) {
      return $( "<li>" )
        .append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
        .appendTo( ul );
    };
  });
  </script>
</head>
<body>
 
<div id="project-label">Select a project (type "j" for a start):</div>
<img id="project-icon" src="images/transparent_1x1.png" class="ui-state-default" alt="">
<input id="project">
<input type="hidden" id="project-id">
<p id="project-description"></p>
 
 
</body>
</html>

Open in new window

You can just as easily substitute for a table or div's to mimic a table.
0
APD TorontoSoftware DeveloperAuthor Commented:
Are you saying that I can base my type-ahead on a HTML table? if so, how, because I can easily format my table the way I need
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Typeahead or any form if it is simply an ajax call and you are returning a response.

The form page submits to the ajaxpage (or same page if the data is static and already on the page), your ajaxpage would accept the get or post and output in the format you want.

You can see the jquery ui example is taking the json data and placing it to an unordered list.  You can either style that list to look like a columns or use div's or a table.

Since these type aheads submit a get or post with one field, if you have two fields such as a first name and last name, on the ajaaxpage, use your scripting to break out the two names using the space as a delimiter.  There are some gotcha's there, but it works.  I have done this where I look for an @ sign for an email or the first character is a number then search for a phone number.

The key is you can manipulate the response to your liking.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
APD TorontoSoftware DeveloperAuthor Commented:
Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.