Solved

Need to fill dropdown data based on another drop down

Posted on 2009-07-08
3
424 Views
Last Modified: 2012-05-07
What I am looking for is I have two columns of data in a sql database, here is what it looks like:

Table si_item_types
Columns
Item            Type
Monitor            Large CRT
Monitor            LCD 17
Monitor            LCD 19
Monitor            LCD Large
Monitor            Small CRT
PC            Windows 2000
PC            Windows XP
Phone            4621SW
Phone            8410B
Phone            8410D

Table si_item
Columns
Item
Monitor
PC
Phone

What I want to do is have one drop down with Monitor, PC and Phone and if you select Monitor lets says it will display all the items in si_item_types that have the Item Monitor in the second dropdown. Do I need to use Javascript or can I use PHP to do this, can some one point me in the right direction. Thanks
0
Comment
Question by:arraysg2008
3 Comments
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24810358
I think javascript would do, since i dont know PHP ;-).

Use Onchange  event on the Select box for drop down with Monitor, PC and Phone.

In the Onchange function submit the form with the selected value and query the db using tht and re-populate the other drop down.

<select name="item" OnChange="sendValue(this.value)">

</select>

<script>
 function sendValue(selValue){
  //send it to the action as query param.
}
</script>


-Murali*
0
 
LVL 6

Accepted Solution

by:
coolersport earned 250 total points
ID: 24810464
There are many similar questions + answers on the net. Please refer to some of them:
- http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23687497.html
- http://codestips.com/php-ajax-cascading-dropdown-using-mysql/

As in your case, it requires communication between client and server for fetching data. Therefore, just javascript would not be sufficient to do the job. If you insist, it can be done with just javascript but all data need to be loaded in advance.

See if those examples up there can answer your question.

Cheers,
Tien
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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

930 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

13 Experts available now in Live!

Get 1:1 Help Now