Double Dynamic Dropdown

pcheng 29 Dec, 2011
Hello everyone,

I started using the Dynamic Dropdown found in Utilities but I can't seem to get it to work. Here is my situation:

I have a table which contains leagues and teams. For example:
Champions League - Manchester Utd
Champions League - Manchester City

English Premier League - Manchester Utd
English Premier League - Liverpool

(I am not a real football fan so forgive me if I don't know a lot of team names🙂 )
I want two dropdown lists. The first one will show the leagues and the second the teams that are in that specific league. So, if someone chooses Champions League on the first dropdown then the second one should only show Manchester Utd and Manchester City.

I got the first dropdown to work by adding the following code as a Custom Element. I think I should be able to do it using a DB Multiple Loader.

<?php
    $db =& JFactory::getDBO();
    $query = "SELECT DISTINCT `league` FROM `#__chronoforms_data_frmTeam2League` ORDER BY `league`;";
    $db->setQuery($query);
    $data = $db->loadObjectList();
?>
<select class="modal" id="league" size="1" title="league" name="league" width="200" style="width: 200px">
  <option value="">------------</option>
<?php
    foreach($data as $d) {
      echo "<option value='".$d->league."'>".$d->league."</option>";
    }
?>
      </select>


Any ideas on how I could do this?


Thanks,

Pericles
GreyHead 29 Dec, 2011
Hi Pericles,

I'm not sure how the new Dynamic dropo-down works :-( I've read the help but it's not very clear. I'll need to experiment.

I don't know if the DB Multi-Record Loader supports DISTINCT - I think not :-(

Meanwhile the code for a double drop-down using Ajax in CFv4 is in my help document that you can buy here - there's also a free article on the site about creating doble-drop-downs using option groups but I suspect your list is a bit long for that to work smoothly.

Bob
This topic is locked and no more replies can be posted.