DropDown List and DB Record Loader

moshiani 10 Feb, 2012
Hi,

I'm a complete novice with chronoforms,php so please excuse me if I'm asking something which has already been answered before. I've searched the forums but haven't found a tutorial that explains this.

In summary on my form the first item I have is a custom element, a dropdown list of countries which I populate from the database using the following code:
<?php
$options = array();
$options[] = "<option value=''>--?--</option>";
$db =& JFactory::getDBO();
$query = "
  SELECT `code`, `name`
    FROM `#_chronoforms_data_country_form`
    ORDER BY `name`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
foreach ( $data as $d ) {
  $options[] = "<option value='{$d->code}'>{$d->name}</option>";
}
?>
This works fine and I see my list of country names in the drop down list, beside the list I have a submit button.

When user selects country and hits submit, I want to populate some text fields on the same form with data associated with the selected country (from the same database table #_chronoforms_data_country_form). I've put a DB record loader event here (is this the correct approach?), also I'm not sure I have configured it correctly! I see a 'request param field' on DB record loader event, how do I tie the value from my dropdown list to this parameter? Is there a tutorial someone can guide me to which can help me understand this.

Thanks, eagerly waiting a response.
GreyHead 10 Feb, 2012
Hi moshiani,

I'm not clear what you want to do here. You say that you want to display results in the same form after the user clicks submit. That's possible, but more often you either (a) go to a second form and display the results there or (b) use JavaScript or Ajax to display the results when the the drop-down country election changes.

Bob
moshiani 10 Feb, 2012
Thanks for your response and suggestion. I have now split this over two forms, the first one has a dropdown list of countries and the second one has country information.

In the first form (with the dropdown list) do I put the Load JS event on the OnLoad event? I did this but it doesn't seem to load the second form when the dropdown list changes.
GreyHead 10 Feb, 2012
Hi moshiani ,

What JavaScript have you put into the Load JS box? There hasn't been any in this thread. And how is that going to help you get the Country information?

Bob
moshiani 14 Feb, 2012
Hi Bob,

I got this to work by adding the JS onChange code after the code which populated the dropdown list. I just pass the dropdown menu to the onChange function, get the selected index and reload the form data from db based on the index.

Thanks for your help.
This topic is locked and no more replies can be posted.