Hi all! I’ve got some code on one of my pages. And it should be changing some text items based on change events (change in a dropdown or change for checkboxes) but it’s behaving strangely. The first change event for any of the items doesn’t do anything, but the second time you change it, it starts functioning normally. What am I missing?
The code I’m using is:
$w.onReady( function () {
//TODO: write your page related code here…
let total = 0
let hours = ($w( ‘#Weddinghours’ ).value)
let rate = 300
$w( ‘#checkbox1’ ).checked = false ;
$w( ‘#checkbox2’ ).checked = false ;
$w( ‘#checkbox3’ ).checked = false ;
$w( ‘#checkbox4’ ).checked = false ;
$w( ‘#checkbox5’ ).checked = false ;
$w( ‘#checkbox6’ ).checked = false ;
$w( ‘#checkbox7’ ).checked = false ;
$w( ‘#checkbox12’ ).checked = false ;
$w( ‘#checkbox13’ ).checked = false ;
$w( ‘#checkbox14’ ).checked = false ;
$w( ‘#checkbox15’ ).checked = false ;
$w( ‘#checkbox16’ ).checked = false ;
calculateTotal()
})
function calculateTotal() {
let total = 0
let hours = ($w( ‘#Weddinghours’ ).value)
let rate = 300
if ($w( ‘#checkbox1’ ).checked) { total += Number($w( ‘#checkbox1’ ).value) }
if ($w( ‘#checkbox2’ ).checked) { total += Number($w( ‘#checkbox2’ ).value) }
if ($w( ‘#checkbox3’ ).checked) { total += Number($w( ‘#checkbox3’ ).value) }
if ($w( ‘#checkbox4’ ).checked) { total += Number($w( ‘#checkbox4’ ).value) }
if ($w( ‘#checkbox5’ ).checked) { total += Number($w( ‘#checkbox5’ ).value) }
if ($w( ‘#checkbox6’ ).checked) { total += Number($w( ‘#checkbox6’ ).value) }
if ($w( ‘#checkbox7’ ).checked) { total += Number($w( ‘#checkbox7’ ).value) }
if ($w( ‘#checkbox12’ ).checked) { total += Number($w( ‘#checkbox12’ ).value) }
if ($w( ‘#checkbox13’ ).checked) { total += Number($w( ‘#checkbox13’ ).value) }
if ($w( ‘#checkbox14’ ).checked) { total += Number($w( ‘#checkbox14’ ).value) }
if ($w( ‘#checkbox15’ ).checked) { total += Number($w( ‘#checkbox15’ ).value) }
if ($w( ‘#checkbox16’ ).checked) { total += Number($w( ‘#checkbox16’ ).value) }
$w( '#additions' ).text = String(total)
if ($w( ‘#checkbox17’ ).checked) { rate += Number($w( ‘#checkbox17’ ).value) }
$w( ‘#rate’ ).text = String(rate)
let final = (hours * rate) + total
$w( ‘#total’ ).text = String( final )
}
export function Weddinghours_change() {
$w( “#Weddinghours” ).onChange( () => {calculateTotal();
});}
export function checkbox17_change() {
$w( “#checkbox17” ).onChange( () => {calculateTotal();
});}
export function checkbox1_change() {
$w( “#checkbox1” ).onChange( () => {calculateTotal();
});}
export function checkbox2_change() {
$w( “#checkbox2” ).onChange( () => {calculateTotal();
});}
export function checkbox3_change() {
$w( “#checkbox3” ).onChange( () => {calculateTotal();
});}
export function checkbox4_change() {
$w( “#checkbox4” ).onChange( () => {calculateTotal();
});}
export function checkbox5_change() {
$w( “#checkbox5” ).onChange( () => {calculateTotal();
});}
function checkbox6_change() {
$w( “#checkbox6” ).onChange( () => {calculateTotal();
});}
export function checkbox7_change() {
$w( “#checkbox7” ).onChange( () => {calculateTotal();
});}
export function checkbox13_change() {
$w( “#checkbox13” ).onChange( () => {calculateTotal();
});}
export function checkbox14_change() {
$w( “#checkbox14” ).onChange( () => {calculateTotal();
});}
export function checkbox15_change() {
$w( “#checkbox15” ).onChange( () => {calculateTotal();
});}
export function checkbox16_change() {
$w( “#checkbox16” ).onChange( () => {calculateTotal();
});}
export function checkbox12_change() {
$w( “#checkbox12” ).onChange( () => {calculateTotal();
});}