Solved

HTML multiple column drop down select box

Posted on 2013-11-02
5
4,095 Views
Last Modified: 2013-11-12
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.
0
Comment
Question by:dcjsdts
  • 2
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
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&
0
 

Accepted Solution

by:
dcjsdts earned 0 total points
Comment Utility
I decided to go with optgroups within my SELECT statement.  This allowed me to at least narrow down my "primary" and "secondary" column.  Although per each optGroup, I have nearly 1,000 entries, at least when I click the drop down and select my choice I can refer to the header.  I kept the points low as to avoid wasting anyone's time.

SOLUTION:

function setDevices(elem){
document.getElementById('NewModel').value = elem.options[elem.selectedIndex].parentNode.label;
 }

Open in new window


<select size="1" style="width:100;" id="NewTag" name="NewTag" onChange="setDevices(this);">
	<option selected><? print($row[NewTag]); ?></option>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
	</select>

Open in new window

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Using optgroups open other possibilities, but a closed under valued question is not the place to explore that.

Cd&
0
 

Author Closing Comment

by:dcjsdts
Comment Utility
Self closed
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now