Condiional dropdown

Status
Not open for further replies.

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'
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();
the file user_ajax.php:
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>";
        }
    }

}
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

First if you haven't, use firefox and install the firebug (www.getfirebug.com) plugin.
Then activate it for your page.
Now do you get any javascript errors?
Still in firebug, you should be able to see the ajax request going to the server and be able to inspect the content returned by the server to the page, does it look right?
Also if you can post the url of the page so we can all look at it

Cheers
Rob
 
Have you worked out how to drive FireBug yet?

The first thing to do is look at the Net tab, which shows you all the activity between your browser and the client for each page load and subsequent AJAX calls. In this case there isn't any, as the AJAX isn't firing when you select the menu.

Looking at the page source, it looks like you still have the comments in the JS. Please read the whole thread you referenced in your first post. There is discussion in there about having to remove all the comment lines. Also, are you using my modified code (from around post #62 in that thread)?

-- hugh
 
Hi Hugh,
I've follow the instructions in the post #61 in the first thread:
I've created the new files user_ajax.php and 2.js and put them in rispective folder (you find them attached)
Now Firebug give me the error:
$(dropdown) is null
$(dropdown).replaceWith(newelement);
???

I cant understand what's wrong....

http://test.enneuno.it/j10/index.php?option=com_fabrik&Itemid=2
 

Attachments

  • files.zip
    1.5 KB · Views: 214
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top