CalcBuilder Forum

Javascript events cb_setValue

User reedjeffry 2015-11-04 11:20:24


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

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

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.

Moonsoft support 2015-11-04 13:23:40

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


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 '':


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:


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.


Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!

Perfect for small code changes or to correct any bug at your site

Buy now!