Solved

Need to fill dropdown data based on another drop down

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

688 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