Hello again,
In my form I have a field user_points___anzahl_naechte where the user should write a number.
In the field below user_points_points I want to calcuate the points by using the number in user_points___anzahl_naechte * 100
If I set the user_points___points as a calc field it works perfect but the user should have the possibility to change the value. So I decided to use instead of calc a normal field and calculate the value with the default.
But than I cant use ajax and my value will not be changed/updated if another number is entered in user_points___anzahl_naechte.
So I looked at the forum and found out than I can use User Ajax.
I put the following code in the user_ajax.php file in components/fabrik/js
class userAjax {
function getData(){
$db =& JFactory::getDBO();
$retStr = '';
$identifyElement = JRequest::getVar('identify', '');
$query = "SELECT anzahl_naechte from user_points WHERE points = '$identifyElement' LIMIT 1";
$db->setQuery($query);
$results = $db->loadResult();
echo $results;
}
}
I also created a form_21.js file with the following code:
function getInfo(){
var url='index.php?option=com_fabrik&format=raw&controller=plugin&c=plugin&task=userAjax';
var identify = $('user_points___anzahl_naechte').getValue(); //field to set JS event on
var update = $('user_points___points'); //field to update
new Ajax(url,{
data:{method:'getData', //enter the function name as you have it in the user_ajax.php
'identify':identify},
onComplete:function(r){
update.value = r; //there are many ways to display the results depending on what you are doing. I am going to return the value to a field.
}
}).request();
};
and in my element user_points___points I set a javascript on change to getInfo();
Unfortunately this dindt work.
Can someone help me what I did wrong?
Thanks and kind Regards,
joki94
In my form I have a field user_points___anzahl_naechte where the user should write a number.
In the field below user_points_points I want to calcuate the points by using the number in user_points___anzahl_naechte * 100
If I set the user_points___points as a calc field it works perfect but the user should have the possibility to change the value. So I decided to use instead of calc a normal field and calculate the value with the default.
But than I cant use ajax and my value will not be changed/updated if another number is entered in user_points___anzahl_naechte.
So I looked at the forum and found out than I can use User Ajax.
I put the following code in the user_ajax.php file in components/fabrik/js
class userAjax {
function getData(){
$db =& JFactory::getDBO();
$retStr = '';
$identifyElement = JRequest::getVar('identify', '');
$query = "SELECT anzahl_naechte from user_points WHERE points = '$identifyElement' LIMIT 1";
$db->setQuery($query);
$results = $db->loadResult();
echo $results;
}
}
I also created a form_21.js file with the following code:
function getInfo(){
var url='index.php?option=com_fabrik&format=raw&controller=plugin&c=plugin&task=userAjax';
var identify = $('user_points___anzahl_naechte').getValue(); //field to set JS event on
var update = $('user_points___points'); //field to update
new Ajax(url,{
data:{method:'getData', //enter the function name as you have it in the user_ajax.php
'identify':identify},
onComplete:function(r){
update.value = r; //there are many ways to display the results depending on what you are doing. I am going to return the value to a field.
}
}).request();
};
and in my element user_points___points I set a javascript on change to getInfo();
Unfortunately this dindt work.
Can someone help me what I did wrong?
Thanks and kind Regards,
joki94
Last edited: