Php Two Combo box in a form control each other. How?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azadms
Forum Newbie
Posts: 5
Joined: Sat Oct 24, 2009 7:28 am

Php Two Combo box in a form control each other. How?

Post by azadms »

On php page in a form, One combo box has list of my Customer from mysql table customer. Another combo box has invoiceno stored in invoice table which has respective customer records.
I want to select customer from first combo box and filter invoiceno from the second one automatically according to the customer.
Any one help me for php or java or Jquery or both codeings? Means if I select customer1 then in the second combo box should show all invoiceno respective to the custermer1.
No Refresh or ReLoad or Post form Pl. Even If I get the first selection in a php variable format example $customer, it is enough for me. Thanks for any one help me.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Php Two Combo box in a form control each other. How?

Post by josh »

Javascript & http requests. (JSON, XML [ajax], etc.)

I actually have a free script (its a plugin for Magento). It does this. http://vehiclefits.com/ The open source "free version" is here (scroll to bottom for download link http://vehiclefits.com/download.php?gateway_bypass=1 )

You can even demo it, and view the javascript in your browser. http://demo.vehiclefits.com/index.php

I recommend the firebug extension for reverse engineering my script or engineering your own.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Php Two Combo box in a form control each other. How?

Post by califdon »

azadms wrote:On php page in a form, One combo box has list of my Customer from mysql table customer. Another combo box has invoiceno stored in invoice table which has respective customer records.
I want to select customer from first combo box and filter invoiceno from the second one automatically according to the customer.
Any one help me for php or java or Jquery or both codeings? Means if I select customer1 then in the second combo box should show all invoiceno respective to the custermer1.
No Refresh or ReLoad or Post form Pl. Even If I get the first selection in a php variable format example $customer, it is enough for me. Thanks for any one help me.
Depending on how many invoices you have, you can approach it in either of these 2 ways:
  • If there are only a few invoices, you could load ALL the data into Javascript arrays to begin with and then do all the work in Javascript.
  • If there is a large number of invoices, that could cause the page to load slowly, so in that case, you would, of course, have to return to the server for specific data each time a different customer is selected. If you wish to avoid a page reload, you will need to use AJAX to obtain the data from a server script that doesn't reload an entire page.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Php Two Combo box in a form control each other. How?

Post by josh »

My example code also implements both of those strategies, (shameless plug).. The offline is definitely not good for very large databases, the ajax is pointless for very small ones.
Post Reply