Hey Guys,
Im fairly new to coding, so please bear with me. I have two Inputs on my site, I want the user to be able to enter a value into both and the #total.text will add them together. I have got as far as the below, which works, but one replaces the other rather than them being added. Can someone please help!? Thanks
export function input1_change_1(event, $w) {
let price = Number(449);
let selectedQuantity = Number(event.target.value);
$w('#total').text = String(850+ (selectedQuantity * price));
}
export function input2_change_1(event, $w) {
let price = Number(39);
let selectedQuantity = Number(event.target.value);
$w('#total').text = String(selectedQuantity * price);
}
Thanks!
I can't seem to make that work. I wonder if I lay out what calculation I am trying to do, that might help?
What I need to do is:
Input 1: Value * 1 = X1
Input 2: Value * 0.02 =X2
Input 3: Value * 1 = X3
Input 4: Value * 0.04 =X4
X1*X2 = Y1
X3*X4 = Y2
Y1+Y2 = Y3
then,
Input 1: Value * 1 = X5
Input 2: Value * 0.14 =X6
Input 3: Value * 1 = X7
Input 4: Value * 0.15 =X8
X5*X6 = Y4
X7*X8 = Y5
Y4+Y5 = Y6
Total = Y6-Y3
This is the input form, if it helps to visualise...
Really appreciate your help!
Jon
Hey, how would I add more inputs to the above code?
Works perfectly! Thanks
Do you mean something like;
$w.onReady(() => { let price1 = 0; let price2 = 0; $w("#input1, #input2").onChange(event => { let target = event.target.id; let newVal = Number($w("#" + target).value); target === "input1" ? price1 = 449 * newVal : price2 = 39 * newVal; $w("#total").text = (price1 + price2).toLocaleString(); }) })