Fill a field with the result of a javascript calculation

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Fill a field with the result of a javascript calculation

Post by fgazza » 2020-10-21 17:38

Hello everybody.

I have a "budget" table with a "human_resource" field, a "hours" field, a "hourly_cost" field and a "allocated_quote" field
The "human_resource" field and the "hourly_cost" field are lookup fields that point to the "name" and "h_cost" fields of the "human_resources" table respectively. In the "budget" table the "hourly_cost" field is filled in automatically when the "human_resource" field is selected.

I would like to create a javascript code for the "budget" table which, after filling in the "human_resource" and the "hours" field, multiply the "hourly_cost" value by the "hours" value and insert the result in "imputed_quote".

The "imputed_quote" field should however also be editable manually after the automatic compilation.

Can someone help me?

THANK YOU!

Fabiano

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: Fill a field with the result of a javascript calculation

Post by fgazza » 2020-10-22 09:13

HI!

I try this code but it not work!

Code: Select all

$j(function () {
var update_imputed_quote = function () {
var v_hourly_cost = $j('#hourly_cost').val();
var v_hours = $j('#hours').val();
var v_imputed_quote = v_hourly_cost * v_hours;
$j('#imputed_quote').val(v_imputed_quote);
}

$j('#hourly_cost' ).on('change', update_imputed_quote);
$j('#hours' ).on('change', update_imputed_quote);

});

I suspect tha the problem is that the hourly_cost field is a lookup field taked from the cost_for_hour field of the hourly_costs table.

So I cannot find the right code to make my code work.

Anyone can help me?

THANK YOU!

Fabiano

Post Reply