please help
i?ve been trying it for many days, but there is no chance... the first dropdown displays the countries and the second dropdown doesn?t change.. nothing happens? what?s wrong?
i think i did everything described in the thread...
the tables are named: countries & towns
the table with the dropdowns is called: jos_fabrik_formdata_5
the 1st dropdown element?s name is country - the 2nd: town
country-table: jos_fabrik_formdata_9
town-table: jos_fabrik_formdata_10
my elements in the table countries:
name: time_date.........................label: time_date
name: fabrik_internal_id................label: id
name: id....................................label: id
name: label................................label: label
my elements in the table towns:
name: time_date.........................label: time_date
name: fabrik_internal_id................label: id
name: id....................................label: id
name: country_id........................label: country_id
name: label................................label: label
is this correct?
this is my actionskript-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 = 'jos_fabrik_formdata_10';
//these are the fields in the 'towns' table
var key = 'id';
var label = 'label';
var foreignkey = 'country_id';
// this is the html id of the drop down element we want to update
var dropdown = 'jos_fabrik_formdata_5___town';
//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=userP luginAjax&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();
and this is my user_ajax.php:
<?php
/**
* @package fabrik
* @version 905 | fabrik_cheesegrits | 2008-05-19 21:21:05 +0200 (Mon, 19 May 2008
* @Copyright (C) Rob Clayburn
* @license GNU/GPL
http://www.gnu.org/copyleft/gpl.html
*/
/**
* This is an example file. To use userAjax, copy this file to user_ajax.php,
* and insert your function into the userAjax class, as per the example
* userExists() function. To call your AJAX method, use a URL of this format from
* your custom JS code:
*
* index2.php?option=com_fabrik&no_html=1&task=userPl uginAjax&method=userExists&username=" + myUsername;
*
* Fabrik will automatically try and call the function name specified in your 'method='.
* You are responsible for grabbing any other parameters, using mosGetParams,
* as per the $myUsername exmaple in userExists() below.
*
* The userExists() example is designed to test if a username given in a text element
* exists. If it does, an alert will pop up, then the field will be cleared and the cursor re-focused to it.
*
* The easiest way to call AJAX from your JS is to use the Mootools Ajax class, for instance:
*
* function userExists(myUsername,refocus) {
* var url = "index2.php?option=com_fabrik&no_html=1&task=u serP luginAjax&method=userExists&username=" + myUsername;
* new Ajax(url, {
* onComplete: function(response){
* if (response != '') {
* alert(response);
* refocus.value = '';
* refocus.focus();
* }
* }
* }).request();
*}
*
* In this case, the above code is called from the 'onchange' trigger
* of a text element like this:
*
* var thisElement = $('jos_fabrik_formdata_13___username');
* var myUsername = thisElement.value;
* userExists(myUsername,thisElement);
*
* Note that there may be better ways of doing this, the above is just the way I found
* to get it done. The element JS grabs the content of the text field, and also supplies
* the element object, so the userExists() function can then empty and refocus if the
* specified username already exists.
*
* Another example of using Mootools Ajax might be something like this, which assumes a function
* in this file called buildStateDropDown() (not shown here), which would build the dropdown
* menu for a list of states which you want to update on the fly (for instance if you
* have a "Country" dropdown, and wish to repopulate the State menu when it changes):
*
* function ajaxTest() {
* var url = "index2.php?option=com_fabrik&no_html=1&task=u serP luginAjax&method=getStateDropDown";
* new Ajax(url, {
* method: 'get',
* update: $('jos_fabrik_formdata_13___states')
* }).request();
* }
*
* The important note here is the 'update' parameter, which tells Mootools the ID of the
* form element you want to replace with the AJAX response.
*
*/
/* MOS Intruder Alerts */
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, 'table');
$key = mosGetParam($_REQUEST, 'key', 'id');
$label = mosGetParam($_REQUEST, 'label', 'label');
$foreignKey = mosGetParam($_REQUEST, 'foreignkey', 'country_id');
$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>";
}
}
}
please, please help me!!! firebug is already running but i?m not sure to understand it?! how can i see the problem?
hope 2 hear from u soon!