Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default PHP Chain Select Box's...

    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.
    Im not here to be loved, I love to be hated :-}


  2. #2
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    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.

  3. #3
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Trinity View Post
    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.
    Im not here to be loved, I love to be hated :-}


  4. #4
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    Quote Originally Posted by Lewiie15 View Post
    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?

  5. #5
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    I have a seperate table for companies & sites, alot of data is stored in them, I cba to change anything

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

    +REP..

    Lew.
    Im not here to be loved, I love to be hated :-}


  6. #6
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    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.

    PHP Code:
    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(urldataString, function(j) {
                for (
    i=0lengthi++){
                
    //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
    Last edited by Joe!; 07-12-2010 at 05:49 PM.
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •