Price Quote Calculator

Hi,

I am looking to make a price calculator that looks up the users drop down value selection against a database and returns a price back in a text element box.

I have three elements:
#dropdown1 - yes/no
#dropdown2 - text strings
#slider1 - a number
#subinviteprice - text box for final price to display in

When dropdown1 = Yes, dropdown2 appears, when the user selects an option, it should perform the data query, and lookup the price based on the value in slider1 and if that lies between quantityfrom and quantityto fields. It also lookups in “product” field the value specified of “invitations”.

It then should update #subinviteprice.

Any ideas why it doesn’t work?

Thank you.

import { wixData } from 'wix-data';
export function dropdown1_change(event) {
if ($w('#dropdown1').value === 'Yes')
$w('#dropdown2').expand();
else
$w('#dropdown2').collapse();
}
export function dropdown2_change_1(event) {
wixData.query("Pricing")
.eq("Product", "Invitations")
.eq("Printing", $w("#dropdown2").value)
.lt("Quantityto", $w("#slider1").value)
.gt("Quantityfrom", $w("#slider1").value)
.find()
.then((results) => {
let items = results.items;
let item = items[0];
let quotePrice = item.Price;
console.log(quotePrice);
$w("#subinviteprice").text = "quotePrice";
});
}

You need to convert the value type from string to number. like:

.lt("Quantityto", Number($w("#slider1").value))
.gt("Quantityfrom", Number( $w("#slider1").value))

Hi,

I changed but still nothing?

export function dropdown1_change(event) {
if ($w('#dropdown1').value === 'Yes')
$w('#dropdown2').expand();
else
$w('#dropdown2').collapse();
}
export function dropdown2_change_1(event) {
wixData.query("Pricing")
.eq("product", "Invitations")
.eq("printing", $w("#dropdown2").value)
.lt("quantityto", Number($w("#slider1").value))
.gt("quantityfrom", Number($w("#slider1").value))
.find()
.then((results) => {
let items = results.items;
let item = items[0];
let quotePrice = item.Price;
console.log(quotePrice);
$w("#subinviteprice").text = "quotePrice";
});
}


Maybe no value fits to your query.
Try to console.log() the results.
also add a .catch() with console.log() the err.

@jonatandor35 got it to work. All i cant figure out is that when the slider1 element value changes at anytime, I want to run another list of functions so it runs the export functions everytime on change:

export function slider1_change(event) {
//need code to run list of other functions when this function runs
}

How can I call a list of functions i.e. function dropdown2_change_1 within this?

Thank you.

import { wixData } from 'wix-data';
export function slider1_change(event) {
//need code to run list of other functions when this function runs
}
export function dropdown1_change(event) {
if ($w('#dropdown1').value === 'Yes')
$w('#dropdown2').expand();
else
$w('#dropdown2').collapse();
if ($w('#dropdown1').value === 'Yes')
$w('#subinviteprice').expand();
else
$w('#subinviteprice').collapse();
}
export function dropdown2_change_1(event) {
let invitationQuery = wixData.query("Pricing")
.eq("product", "Invitations")
.eq("printing", $w("#dropdown2").value)
let invitationquantQuery = wixData.query("Pricing")
.le("quantityfrom", $w("#slider1").value)
.ge("quantityto", $w("#slider1").value)
invitationQuery.and(invitationquantQuery)
.find()
.then((results) => {
let items = results.items;
let item = items[0];
let quoteprice = item.price;
console.log(results);
let guestquantity = Number($w('#slider1').value);
$w('#subinviteprice').value = "£" + (guestquantity * quoteprice);
});
}

got it is was using this in an export function on change

functionname();