Log in

View Full Version : PHP Chain Select Box's...



LMS16
07-12-2010, 02:40 PM
Hi,

I'm in need of a solution for the following:

I need chain box's so that box 1 select all companies from a database. When that company is selected, it shows a second chain box with sites attached to it....

I found something like it here: http://bonrouge.com/~chain_select_ajax

I basically need this, but for box 1 fetch all companies from the database & box 2 to refresh & show all sites attached to it.

+REP for any help.

Lew.

Trinity
07-12-2010, 03:24 PM
Can't you use the page that you linked to?
Make a table with the companies in one column and the name of the sites attached to it in the next column, separated by |, then just adjust the PHP on that page a bit and boom. Done.

LMS16
07-12-2010, 03:28 PM
Can't you use the page that you linked to?
Make a table with the companies in one column and the name of the sites attached to it in the next column, separated by |, then just adjust the PHP on that page a bit and boom. Done.

That is what I'm trying to avoid. There must be a way to change it... maybe using query to refresh the select box or post the contents from the first select box... ARGHH, confusing!

Lew.

Trinity
07-12-2010, 03:31 PM
That is what I'm trying to avoid. There must be a way to change it... maybe using query to refresh the select box or post the contents from the first select box... ARGHH, confusing!

Lew.

Why are you trying to avoid it?

LMS16
07-12-2010, 03:37 PM
I have a seperate table for companies & sites, alot of data is stored in them, I cba to change anything :P

I might just put it in an iframe and use an onchange event to do it :)

+REP..

Lew.

Joe!
07-12-2010, 05:43 PM
If the two tables are linked, which I would hope they are somehow. By both having a company ID number I assume. Then you could simply make a script that searches for all websites that belong to a certain ID, which you would query using a get or post request. Then get the script to return you the results and use javascript to populate the select element with the results.


function getWebsites(elementFrom,elementTo)
{
$("#"+element).change(function() {
var url = "SEARCHSCRIPTHERE.php";
var company = $("#"+elementFrom).val();
var dataString = 'c='+ company;
var selectoptions = '';
//alert(dataString);
$("#"+elementTo).html("<option>loading..</option>");
$.get(url, dataString, function(j) {
for (i=0; i < length; i++){
//format your results in this part.

selectoptions = selectoptions+"\n<option>"+EDIT THIS+"</option>";

}
$("#"+elementTo).html(selectoptions);
});
});
}

Example of the javascript, jquery is required though, havn't given you full code, as you should learn ;)

Want to hide these adverts? Register an account for free!