Need Help Creating a Feed Weight Calculator

hi guys thanks for joining i was wondering if anyone one could point me in the right direction i want to build a form where for example

Customer Selects/ Types Data
Dogs Age (drop Down)
Dogs Weight (Type)

Then It Returns Data With The Estimated Feed Amount

Ideally I want to use a data base but im unsure where to start with this one

Thanks In Advance

Something Like The Below Image

Hello Robert,

To do this you would need to get the value for each input field on the page, when a certain event happens, and run those numbers through an algorithm that you have.

It would look something like this: (These are example properties and Id’s for you elements, in this example it is calculated when a button is clicked)

export function button1_click(event, $w){
    let age = $w('#dropdown1').value;
    let foodWeight = $w('#textInput').value;
    let petWeight = $w('#textInput2').value;
    
    
    let total = age * (petWeight/foodWeight);
    
    $w('#text').text = total;
}

Hope this helps,

Majd

i will try it shortly

so in the database it needs to be age(number) etc

im lost how to set this up

Hello Robert,

Ok I will guide you through it step by step:

  1. Turn on developer tools
    2.Go to the page you have this on, and open the code section
  2. Type in the code above and change the ID’s to the ones you have on your page (if you click on an element you will see something that starts with a hashtag: #text1, #button1, etc… that is the ID of the element

4*. To insert it into a database it would look like this:

export function button1_click(event, $w){
    let age = $w('#dropdown1').value;
    let foodWeight = $w('#textInput').value;
    let petWeight = $w('#textInput2').value;
    
    
    let total = age * (petWeight/foodWeight);
    
    $w('#text').text = total;
    
    //Create an object to insert into database, YourCollectionField should be a field in your collection that you made.
    let toInsert = {
        YourCollectionField: total
    }
    
    //Here we insert into database
    wixData.insert('YourCollectionName', toInsert); 
        
}

Goodluck,
Majd