Page 1 of 1
Php Two Combo box in a form control each other. How?
Posted: Wed Jan 05, 2011 12:44 am
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.
Re: Php Two Combo box in a form control each other. How?
Posted: Wed Jan 05, 2011 1:17 am
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.
Re: Php Two Combo box in a form control each other. How?
Posted: Wed Jan 05, 2011 1:30 pm
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.
Re: Php Two Combo box in a form control each other. How?
Posted: Wed Jan 05, 2011 8:17 pm
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.