sergio
New Member
Conditional dropdown
Hi guys
as shown in the thread
http://fabrikar.com/forums/showthread.php?t=6246
I tried to use this feature but don't works... ???
code javascript applied to first element on even 'onchange'
the file user_ajax.php:
The tables are
first: a_stati
fields: id_stat | stati
second a_citta
fields id_citta | id_stat | citta
I checked all the names of fields...
i don't know what I wrong..
I use fabrik 1.0.15 and fabrik at the last SVN
Hi guys
as shown in the thread
http://fabrikar.com/forums/showthread.php?t=6246
I tried to use this feature but don't works... ???
code javascript applied to first element on even 'onchange'
Code:
//get the country id that has been selected by the user
var cid = this.getValue();
// this is the database table name that contains the information you want to display in the town drop down
var table = 'a_citta';
//these are the fields in the 'towns' table
var key = 'id_citta';
var label = 'citta';
var foreignkey = 'id_stat';
// this is the html id of the drop down element we want to update
var dropdown = 'a_citta___citta';
//below here you shouldnt need to edit anything
//we want to create an ajax object to send a request to fabrik's userPluginAjax class - this call contains the variables
//outlined above and update the second drop down with the data returned from the server
var url = 'index2.php?option=com_fabrik&no_html=1&task=userPluginAjax&method=getFields';
url += '&table=' + table;
url += '&val='+cid;
url += '&key='+key;
url += '&label='+label;
url += '&foreignkey='+foreignkey;
new Ajax(url, {
method: 'get',
update: $(dropdown)
}
).request();
Code:
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
class userAjax {
function getFields(){
global $database;
//get all the variables passed in by the ajax objects url
$table = mosGetParam($_REQUEST, 'a_citta');
$key = mosGetParam($_REQUEST, 'key', 'id_citta');
$label = mosGetParam($_REQUEST, 'label', 'citta');
$foreignKey = mosGetParam($_REQUEST, 'foreignkey', 'id_stat');
$val = mosGetParam($_REQUEST, 'val', '1');
//run a query on the database to get the matching fields
$sql = "SELECT $key AS value, $label AS label FROM $table WHERE $foreignKey = '$val'";
$database->setQuery($sql);
$rows = $database->loadObjectList();
//write the results of the query back to the browser - the javascript code will then assign
//the text to the second drop down
foreach($rows as $row){
echo "<option value=\"$row->value\">$row->label</option>";
}
}
}
first: a_stati
fields: id_stat | stati
second a_citta
fields id_citta | id_stat | citta
I checked all the names of fields...
i don't know what I wrong..
I use fabrik 1.0.15 and fabrik at the last SVN