CALCULATE FIELDS AND SAVE TOTAL VALUE IN COLLECTION DATA

this is my form
needs calculation = 선택 읍션 = Select Options
주중 = weekdays. 주말 = weekends - in golf course prices vary depends on number holes a player wants to play and the days wether it falls in weekend or weekdays multiplied by the number of persons

Total : Php 0 - this is a text = where the calculated amount shows

this is the code :

export function Person_change ( event ) {
let person = Number($w ( “#Person” ). value );
let weeks = Number($w ( “#weeks” ). value );
let week2 = Number($w ( “#week2” ). value );

//let total = Number ($w("#input2").value) 

$w ( "#totalLabel" ). text  = ( person  *  weeks ). toString (); 
//$w("#input2").inputType = (person * weeks).toString(); 
$w ( "#totalLabel" ). text  = ( person  *  week2 ). toString (); 
//$w("#input2").inputType = (person * week2).toString();

Sorry, Some how my upper explanation was cut.

Hello!

I am a newbie in coding, and I am trying to build a site that can request a quote
and reserve a date for a specific golf course. I already find a code that can calculate fields and show the total amount, but the problem is the calculated total amount wont save to my dataset collection.

I have read on some of the forums that connecting the “text” to my dataset will not work to save the calculated data. So I tried to use a “textfield” to show the calculated amount, but I got stuck with the codes.

I have also read that I have to use “Hooks” and onBeforesave…
can someone please help me with this ?

thank you so much!!

I figured it out
I used “hook and beforeInsert” to save the calculated amount to my data collection

I based my coding here : https://www.wixgenius.com/tutorial/save-calculated-field-using-wix-data-hooks

THANK YOU FOR THE GREAT TUTORIAL :)) @wixIdeas

here are the updated codes

Page Code :

// CALCULATED FIELDS

export function Person_change ( event ) {
let person = Number($w ( “#Person” ). value );
let weeks = Number($w ( “#weeks” ). value );
let week2 = Number($w ( “#week2” ). value );

$w ( "#totalLabel" ). show (); 

$w ( "#totalLabel" ). text  =  `" ${ String ( weeks  *  Number ( person ))} 페소"` ; 
$w ( "#totalLabel" ). text  =  `" ${ String ( week2  *  Number ( person ))} 페소"` ; 

Backend :

export function GolfandCountryClubData_beforeInsert ( item , context ) {
//TODO: write your code here…
let person = item.persons ; // CONNECT TO NO. OF PERSON DATA
let weeks = item.holes ; // CONNECT TO PRICE AND NO. OF HOLES DATA
var totallabel = String ( weeks * Number ( person ))

let totalprice = Number ( totallabel )

item.totalprice = totalprice ; // CONNECT TO THE TOTAL AMOUNT COMPUTED DATA
return item ;