Writing Calculated fields to Database

Hi,

I have the following code on my page, it is taking Value A and Value B and simply applying a calculation of (AB)/100 and then ((AB)/100)+A

The page is showing the correct results, but on the two user inputed values are being writting to the database after clicking a submit button.

The two calculated fields are not written tto the database? Here is the code on the page:

export function input1_keyPress(event) {
var A = Number($w(‘#input1’).value + event.key);
var B = Number($w(‘#input2’).value);
var C = Number((A * B) / 100);
var D = Number((C + A));

$w('#input3').value = Number(C); 
$w('#input4').value = Number(D); 

}

export function input2_keyPress(event) {
var A = Number($w(‘#input1’).value);
var B = Number($w(‘#input2’).value + event.key);
var C = Number((A * B) / 100);
var D = Number((C + A));

$w('#input3').value = Number(C); 
$w('#input4').value = Number(D); 

}

Do i need to add a hook on the backend to do the calculation to write it to the database?

Hi,
If an element is connected to a dataset, setting the element’s value in code does not set the value of the connected field in the dataset. That means if you use the dataset to perform a submit, the value changed in code is not reflected in the submitted item.
To submit the new value using a dataset, set the field’s value using the setFieldValue () function before performing the submit.

I am experiencing the same . i have two datasets but the code inst working.its an onclick event