Forums

Chronoconnectivity Double Drop-down

zandergraphics 11 Jan, 2012
I am trying to create a double drop down filter in Chronoconnectivity by adapting the Ajax tutorial from Chronoforms. I have the dropdowns in place and can pull in the values from the database fine but it does not appear to be triggering the JS to show the second dropdown. I'm pretty sure that at least part of the problem is this line in the JS file:

var url = "index.php?option=com_chronocontact&chronoformname=Manager&task=extra&format=raw";


but there might be more that needs to get fixed but I know this is part of it so I'm starting there.

There may also be an issue with the placement of the JS code. I have tried an include as well as pasting it into the index file head but I'm not certain if that is an issue yet or not because it could just be the URL in the JS that is causing trouble.

If there is any information anywhere on double drop-downs for Chronoconnectivity, I can't seem to locate it.

Any help would be greatly appreciated.
GreyHead 11 Jan, 2012
Hi zandergraphics,

ChronoConnectivity is more limited than ChronoForms in this respect and doesn't have the facilities to handle Ajax itself.

I assume that you have ChronoForms installed - then you can create a 'dummy' form and just use the Extra Code 1 box for this code. I think that should work OK.

You can put the JavaScript in the CC Header box; I'd use the Joomla! Document methods to load it
<?php $doc =& JFactory::getDocument();
$script = "
// add your script here being careful about double quotes //
";
$doc->addScriptDeclaration($script);
?>


I don't' remember anyone doing a double-drop down for CC before so there is no documentation :-(
zandergraphics 16 Jan, 2012
Excellent. Totally worked!! Thanks!!

In case anyone else is looking for this, here is the complete code I used (or at least the important parts):

<?php $doc =& JFactory::getDocument();
$script = "
window.addEvent('domready', function() {
$('manufacturer').addEvent('change', function () {
var a = $('manufacturer').value;
if ( a != null && a != '' ) {
getModel(a);
} else {
$('ajax_getmodel').setHTML(\"<span id='ajax_getmodel' >Please select a model</span>\")
}
}) ;
});
function getModel(a){
var url = \"index.php?option=com_chronocontact&chronoformname=SelectModel&task=extra&format=raw\";
new Ajax(url, {
method: 'get',
onRequest: function(){
$('progress_getmodel').setStyle('visibility', 'visible');
},
onComplete: function(){
$('progress_getmodel').setStyle('visibility', 'hidden');
},
update: $('ajax_getmodel'),
data: 'sid='+a
}).request();
};
";
$doc->addScriptDeclaration($script);
?>

<table><tr><td>
<?php
if ( !$mainframe->isSite() ) { return; }
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `manufacturer`
  FROM `airplanes` WHERE manufacturer_list='1' ORDER BY manufacturer ASC;
";
$db->setQuery($query);
$data = $db->loadObjectList();
?>
<label class="cf_label" style="width: 150px;">Manufacturer</label>
<select class="cf_inputbox" id="manufacturer" size="1" title="" name="manufacturer">
<?php
foreach($data as $d) {
echo "<option value='".$d->manufacturer."'>".$d->manufacturer."</option>";
}
?>
</select>

</td><td>
<label class="cf_label" style="width: 150px;">Model</label>
<span id='ajax_getmodel' style='color:#444;'>Please choose a model</span>
<span id='progress_getmodel' style='visibility:hidden;' > Searching . . .</span>
<?php
$manufacturer_id =& JRequest::getString('model', '', 'get');
if ( $manufacturer_id ) {
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `model` AS `id`, `model`
FROM `airplanes`
WHERE `model` = '$manufacturer_id'
ORDER BY `model`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
if ( count($data) ) {
$m = new stdClass();
$m->id = 0;
$m->model = '==?==';
$data = array_merge(array($m), $data);
$return = JHTML::_('select.genericlist', $data, 'model',
'class="inputbox required select" size="1" id="model_select" name="model_select" ', 'id', 'model', 0);
} else {
$return = "Sorry, we couldn't find that manufacturer";
}
} else {
$return = "";;
}
echo $return;
?>
</td></tr></table>


And then I created a form called SelectModel and pasted this into the Extra code 1:

<?php
$manufacturer_id =& JRequest::getString('sid', '', 'get');
if ( $manufacturer_id ) {
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `model` AS `id`, `model`
FROM `airplanes`
WHERE `manufacturer` = '$manufacturer_id'
ORDER BY `model`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
if ( count($data) ) {
$m = new stdClass();
$m->id = 0;
$m->model = '==?==';
$data = array_merge(array($m), $data);
$return = JHTML::_('select.genericlist', $data, 'model',
'class="inputbox required select" size="1" ', 'id', 'model', 0);
} else {
$return = "Sorry, we couldn't find that model";
}
} else {
$return = "Sorry, we couldn't find that model";;
}
echo $return;
?>
This topic is locked and no more replies can be posted.