Hi, newbie coder here!
I am trying to create a time sheet form for users to submit their working hours in. i have 7 user input boxes and one extra for the total.
How do I get all 7 boxes to add up and then total in the total box. The code I am trying to use is
$w.onReady( function () {
let total = Number($w( “#input6” ).value) + Number($w( “#input7” ).value) + Number($w( “#input8” ).value) + Number($w( “#input9” ).value) + Number($w( “#input10” ).value) + Number($w( “#input11” ).value) + Number($w(‘#input12’).value);
$w( ‘#input13’ ).value=total
});
$w.onReady(function () {
let myValue1 = Number($w("#input7").value)
let myValue2 = Number($w("#input8").value)
let myValue3 = Number($w("#input9").value)
let myValue4 = Number($w("#input10").value)
let myValue5 = Number($w("#input11").value)
let myTotalSum = 0
for (var i = 0; i < 5; i++) {
myTotalSum = myTotalSum + myValue[i]
}
console.log(myTotalSum)
});
Thanks you. Do I need to define Input 13 as thats where I want the total to appear?
Hey Dima, the myValue variables need to be an array. Something like this:
let myValue[0] = Number($w("#input7").value)
And then this would work:
myTotalSum = myTotalSum + myValue[i];
You could also write it like this:
myTotalSum += myValue[i];