Solved

HTML multiple column drop down select box

Posted on 2013-11-02
5
4,253 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
ID: 39618677
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
ID: 39619991
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
ID: 39632399
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
ID: 39633515
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
ID: 39641107
Self closed
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

862 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

29 Experts available now in Live!

Get 1:1 Help Now