Javascript problem (in joined tables

Status
Not open for further replies.
Hi there,

I have a list that is a join between 3 tables.

jos_users to intra_shops to intra_zone
jos_users->shopid to intra_shops->id then intra_shops->zoneid to intra_zone->id


I have a problem using the (change) javascript on an element on a form

If I enter the one line with hardcoded data 'xxxx'

form_4.formElements.get('jos_users___nlevel').update('xxxx');

then the field nlevel gets updated with 'xxxxx'

HOWEVER

I want to read a field on the form from the zone portion on the form and fill it in on the jos_users section into a new field


When I now replace the line above with the following 2 lines:

var z = form_4.formElements.get('intra_zone___zone_description').getValue();
form_4.formElements.get('jos_users___nlevel').update(z);

IT does nothing.

even if I change the z variable to the hardcoded one
var z = form_4.formElements.get('intra_zone___zone_description').getValue();
form_4.formElements.get('jos_users___nlevel').update('xxxx');

It still does nothing until I remove the 1st line.

I will appreciate ANY advise.


(I am actually an old VBA developer now tampering in FABRIK and so I will most likely ask for more advise)

by the way: I am trying this workaround with the joined tables as I could not wrap my head around the JS and Ajax combination to go and look up the zone description via a SQL query
 
I tested your code, or at least a modified version for my server and it works fine, I also tested in firebug and didn't see any issues.

Code:
var z = form_30.formElements.get('checkboxcalc___description').getValue();

form_30.formElements.get('checkboxcalc___description2').update(z
);


I did however test this on the backend of Fabrik, so maybe try this for starters as there may be something in the front end of your site conflicting.
 
Also working in back end.

No luck (4am now)

When i do a getvalue from the primary table it works.
When i read from the joined secondary tables, nothing

Just something , when I started changing the properties of my field it had a checkbox stating the "properties are linked to shops, unlink". I checked it true and proceeded.

I am assuming that the same field can have different Javascript properties on different joined tables?

I have left joins and in the form and list I can see the correct secondary data that I am trying to read.

is there a way that I can set z by a SQL query in the javascript section?



must sleep a bit now, will try in the morning again
 
I re-read your original post..... I think I know what's going on.

Am I correct in saying that you have never been able to update

intra_zone___zone_description ?


I think you are naturally assuming this is the element name on the form..... however when their are joins involved they are referenced differently.

Your friend in this situation is Firefox and Firebug but in this case you should be able to view the source of the page to find what you want.

If you load your form up in a browser and select view source and search for 'join___' you should be able to find the element name.

It could be called something like

join___3___intra_zone___zone_description


I think this may be the issue anyhow..... If you have the page
online I can take a quick look.
 
Hi Felix,
did that and it moves the data : great! BUT now realised I cannot use the joined table to do that. When I change/allocate the shop the join is where the join WAS. It now moved the OLD description to the main table.

Is there a way to refresh/requery the join midstream before I read the description?

I really must figure out the SQL route rather.
 
The credentials didn't work for me....

I think it would be easier if I saw the page to understand fully what you need. :)
 
Ok, do you mean if you change the dropdown, (shops), to B-level the description in Zone stays at C-level?
 
Yes..

I did some research on the forum and am trying the following now.

1. I copied the user_ajax_example.php to user_ajax.php in the com_fabrik folder

2. I then changed the example function to the following

class userAjax {
function whatzone() {
$db = FabrikWorker::getDbo();
$retStr = '';
$myshopid = JRequest::getVar('shopid', '');
$shopquery = "SELECT zone_id from intra_shops WHERE id = '$myshopid'";
$db->setQuery($shopquery);
$db = setQuery($shopquery);
$myzoneid = $db->loadResult();
$zonequery = "SELECT zone_description from intra_zone WHERE id = '$myzoneid'";
$db->setQuery($zonequery);
$results = $db->loadResult();
echo $results;
}
}

3. I then used my users form (id=1) and added the javascript (change) to the field [shopid]


var theshop = $('jos_users___shopid');
thezone = whatzone(theshop);
form_1.formElements.get('jos_users___nlevel').update(thezone);

not updating the nlevel field withe the zone description as expected.

Am I on the right track?
 
made a small change, thinking the name of the var that I am sending should maybe be the same as the receiving one in the AJAX function? -> still nothing....

var shopid = form_1.formElements.get('jos_users___shopid').getValue();
thezone = whatzone(shopid);
form_1.formElements.get('jos_users___nlevel').update(thezone);
 
"fixed up" the function (thought so thought I had a problem in the $db->setQuery($shopquery);
$myzoneid = $db->loadResult(); area


replaced function is now.


class userAjax {
function whatzone() {
$db = FabrikWorker::getDbo();
$retStr = '';
$myshopid = JRequest::getVar('shopid', '');
$shopquery = "SELECT zone_id from intra_shops WHERE id = '$myshopid'";
$db->setQuery($shopquery);
$myzoneid = $db->loadResult();
$zonequery = "SELECT zone_description from intra_zone WHERE id = '$myzoneid'";
$db->setQuery($zonequery);
$results = $db->loadResult();
echo $results;
}
}
 
Yes you are on the right track and was going to be my next suggestion depending on your reply.

Not sure why you done the double query on the PHP, although thinking about it, it maybe to get the value as it's a join.

Try this.

Ajax

Code:
<?php
defined('_JEXEC') or die('Restricted access');

class userAjax {

    function whatzone() {
        $result = '';
        $db = JFactory::getDBO();
        $Ids = JRequest::getVar("identify", "");  
        $zonequery = "SELECT zone_description from intra_zone WHERE id = '$myzoneid'";
        $db->setQuery($zonequery);
        $results = $db->loadResult();
        echo $results;
    
            
              
        }
}
?>


JS

Place this file in the following directory \components\com_fabrik\js and call it 7.js

So you will have \components\com_fabrik\js\7.js

7 is your main form id that you are loading, i.e if you look at all your forms besides TestJoin33 is 7.


Code:
function getInfo(identify){ 
var url = 'index.php?option=com_fabrik&format=raw&view=plugin&task=userAjax&method=whatzone';

    new Request({
        url: url,
        data: {
        method: 'whatzone', 'identify':identify
        },  

        onComplete:function(r){
        
        form_1.formElements.get('jos_users___nlevel').update(r);

        }
}).send();
};



Then in the element javascript tab for Zone ID keep the action as change but just post this code only.

Code:
getInfo(identify);


I'm not 100% that this will work first time as I'm doing this from my own notes and snippets as I usually test as I'm going through.
 
Hi Felixkat,

I am only in the user list/form now. (form1) I only tried the joined table/s as a workaround. Ideally I want to get zone description.

The reason for my 2 queries was that I am linking a user to a shop. (intra_shops)
As said before I have a intra_zone table as I also link my shops to a zone in a seperate list.

So my thinking was.

1. When I link or change the user's shopid ...then i read the shopid
2. I look for the zone_id in the intra_shop table where id=shopid
3. Then I look for the zone_description in the intra_zone table where id=zone_id

I have to grasp this principle as I have another application looming where I will be looking up prices etc in the same way.

I cannot understand how the way you changed it will bring back the correct zone.Remember I am on the shopid's change event.
 
$myzoneid = JRequest::getVar("identify", "");
$zonequery = "SELECT zone_description from intra_zone WHERE id = '$myzoneid'";

Correction by the way. :)


I see what your saying now, I think. I'm just wondering if this is setup correctly i.e if the joins are the right way round for what you need.


I've got a couple of things going on at the moment, I think I need to re-read the whole thread to be sure I understand. :)
 
Another attempt

Hi Felix

This is now my Ajax bit

defined('_JEXEC' ) or die('Restricted access');

class userAjax {
function moreinfo() {
$db = FabrikWorker::getDbo();
$retStr = '';
$myUserId = JRequest::getVar('user_id', '');
$query = "SELECT 'more_information' from 'user_ajax_more_information' WHERE user_id = '$myUserId '

LIMIT 1";
$db->setQuery($query);
$results = $db->loadResult();
echo $results;

}
function whatzone() {
$db = FabrikWorker::getDbo();
$retStr = '';
$myshopid = JRequest::getVar('shopid', '');
$shopquery = "SELECT zone_id from intra_shops WHERE id = '$myshopid'";
$db->setQuery($shopquery);
$myzoneid = $db->loadResult();
$zonequery = "SELECT zone_description from intra_zone WHERE id = '$myzoneid'";
$db->setQuery($zonequery);
$results = $db->loadResult();
echo $results;
}
function showme() {
$myvalue = 'this is it';
echo $myvalue;
}

}

in order just to understand the js bit i created a 1.js just to see if I can write ANYTHING back into the form via the user_ajax.php and x.js

function getInfo(){
var url = 'index.php?option=com_fabrik&format=raw&view=plugin&task=userAjax&method=showme';
new Request({
url: url,
data: {
method: 'showme',
},
onComplete:function(r){
form_1.formElements.get('jos_users___nlevel').update('test');
}
}).send();
};

in my users shopid change javascript i popped in
getinfo();


NOTHING
 
trying something else (again) to get the basics understood.

I have a function in user_ajax.php as follows:

function showme() {
$mypassed = JRequest::getVar('passvalue', "");
$myvalue = $mypassed;
echo $myvalue;
}


I am now trying to send a value from 1.js into this function and let THAT function update my field

the function in 1.js is:

function getInfo(showthis){
var url = 'index.php?option=com_fabrik&format=raw&view=plugin&task=userAjax&method=showme';

new Request({
url: url,
data: {
method: 'showme', 'passvalue': showthis
},
onComplete: fromphp=url

}).send();

form_1.formElements.get('jos_users___nlevel').update(fromphp);

};



So:
I want to call the showme() function with values that I send into it and load THAT answer into fromphp

I did get the bits to work but cannot get the value from the user_ajax function yet.

Any help will be greatly appreciated
 
Using Firebug within Firefox really helps in these situations as it can show you whats going wrong.

I have made some changes as there were some syntax errors but I really need something like eXtplorer on you server so I can see the ajax files.
 
Here is an example JS for an AJAX call based on one that is working for me. Note 'getDrillInfo' is the method in my user_ajax.php.

Code:
function ajaxDrillInfo() {
    var url = 'index.php?option=com_fabrik&format=raw&view=plugin&task=userAjax&method=getDrillInfo';
    var drill_id = form_1.formElements.get('mps_score___drill_id').getValue();
 
    new Request({
        url: url,
        data: {
        method: 'getDrillInfo', 'drill_id': drill_id
        },
    onComplete: function(r){
        form_1.formElements.get('mps_score___title').update(r);
        }
    }).send();
}
 
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