Solved

Need to fill dropdown data based on another drop down

Posted on 2009-07-08
3
422 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

23 Experts available now in Live!

Get 1:1 Help Now