Solved

Need to fill dropdown data based on another drop down

Posted on 2009-07-08
3
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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)

733 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