Forum


Calc Builder Support

Calc Builder support
Forums
No se permite escribir sin estar logado. Por favor, login

Javascript events cb_setValue 04.11.2015 11:20

HI,

I am not understanding Javascript events: cb_getValue and cb_setValue, or at least not observing what I expected. I need to do calculations, but just for testing purposes, consider

Fields:
averageSalary (Type: Number)
benefits (Type: Number)
annualSalary (Type: Number)
monthlySalary (Type: Number)

Javascript events, Executed before calculate execution

//Get Value from Field
//var result=cb_getValue('myvar');
var averageSalaryResult=cb_getValue('averageSalary');
var benefitsResult=cb_getValue('benefits');

//Set Value from Field
//cb_setValue('myvar','NEW_VALUE');
cb_setValue('annualSalary','averageSalaryResult');
cb_setValue('monthlySalary','benefitsResult');

When I enter a number in averageSalary and benefits, I expected to see the numbers in fields annualSalary and monthlySalary. However, the text "averageSalaryResult" and "benefitsResult" is shown.

Re: Javascript events cb_setValue 04.11.2015 13:23

Hi,
at your code you're getting the values of the two fields, and then setting a new values for the other fields. As you're using

cb_setValue('annualSalary','averageSalaryResult');

you're setting a fixed text 'averageSalaryResult' to that input. In case you want to use the value you have just recovered from the other field, use without '':

cb_setValue('annualSalary',averageSalaryResult);


For setting 'result' values inside the input form, you can follow other different approach as well, using inline fields:

- Change the type of the destination fields from 'text' to 'inline result'
- Now at the code section (the main php code, not the js tabs), you can set your calculated value to that fields, for ex:

$annualSalary=$averageSalaryResult;


This will change 'annualSalary' value each time user changes values at the form.


Hope this helps, please let us know if you need further help with this.


Regards
Moonsoft Team
www.moonsoft.es
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect
FaLang translation system by Faboba

Lo que nuestros clientes opinan de nosotros