Link to home
Start Free TrialLog in
Avatar of dcjsdts
dcjsdts

asked on

HTML multiple column drop down select box

Hi folks,

This is actually related to a PHP page pulling from a MySQL DB, but I'll figure out the rest once I get a working demo.

What I need is to click on an HTML dropdown box that currently displays an index number but when clicked it displays three fields of the data in the drop down.  Then when the user makes a choice and it displays only the left, indexed field and onChange it populates a text/input field with the second column of data.  Another text field with the 3rd column of data, etc.

Real life scenario:  Asset tag, computer and serial number.  User is on a web page and they have a choice to select an available computer.  They see a drop down that is a list of asset tags.  They click the dropdown and it shows "12345 - HP8300 - SN1GGY", "12346 - HP8250 - SN3JB77",  "12347 - HP7700 - HK71SB"  and so on.

They make a choice of "12345 - HP8300 - SN1GGY" and it returns just "12345" in the visible page/field/box and after they select it, it populates the adjacent fields with "HP8300" and "SN1GGY".  This seems so very simple and common.

 I'm thinking that maybe as an alternative there is a select/dropdown that always contains all this concatenated data and acts as a "button" or selection tool and this populates my other fields after update.  This selection object would not be connected to any data field, it would just populate my other data fields.
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Do you want 2 drop down selects?  I use http://www.appelsiini.net/projects/chained
 
Your html is created as below.  You can see the selected value of option 1 is then linked to the class in the 2nd select.  In your php/mysql, you would simply created the select and then option values dynamically by looping.  The 2nd drop down you would have to have a query in your db with the linkage.  
<select id="mark" name="mark">
  <option value="">--</option>
  <option value="bmw">BMW</option>
  <option value="audi">Audi</option>
</select>
<select id="series" name="series">
  <option value="">--</option>
  <option value="series-3" class="bmw">3 series</option>
  <option value="series-5" class="bmw">5 series</option>
  <option value="series-6" class="bmw">6 series</option>
  <option value="a3" class="audi">A3</option>
  <option value="a4" class="audi">A4</option>
  <option value="a5" class="audi">A5</option>
</select>

Open in new window

Then a jquery call
$("#series").chained("#mark");

Open in new window


And all of this assumes you have the your js for jquery and chained loaded
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.chained.min.js"></script>

Open in new window

If you are actually looking for a multi-column select you are wasting your time.  Such a thing does not exist and probably never will.

You can probably style a table or widget comprised of divs to simulate what you want, but it will not  be a functional select.

If you want to use the more rational approach of using adjacent selects, then what padas is giving you is the way to go, and is worth more than the paltry 50 points you offered.

Cd&
ASKER CERTIFIED SOLUTION
Avatar of dcjsdts
dcjsdts

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using optgroups open other possibilities, but a closed under valued question is not the place to explore that.

Cd&
Avatar of dcjsdts
dcjsdts

ASKER

Self closed