Can't Get Basic Functionality to Work

I am new to WIX and I can’t seem to get basic things working.

All I want to figure out right now is how to take input from 3 fields and add it to the Collection. I have a dataset for the aircraft list.
Issues:

  1. Aircraft list does not populate in the dropdown. It does when I do page preview though.

  2. Nothing happens when I click the button. No records are inserted.

  3. I also notice that nothing goes to the Console Log when I try Preview the page.

Here is my code. What am I doing wrong?

import wixData from ‘wix-data’ ;

$w( “#button3” ).onClick(insertFlight)

export function insertFlight(event, $w){
let flight = {
“Origin” : $w( “#originICAO” ).value,
“Destination” : $w( “#destinationICAO” ).value,
“Aircraft” : $w( “#aircraft” ).value

};

console.log( “Flight to be saved” + JSON.stringify(flight));

wixData.insert( “PlannedFlights” , flight)
.then( (results) => {
flight = results; //see item below
console.log( "Flight in db: " + JSON.stringify(flight));
} )
. catch ( (err) => {
let errorMsg = err;
} );
}

OK. I think I figured out one thing. All you actions should be within the OnReady event.

$w( " #button3 " ).onClick(insertFlight)

Should be:

$w( " #button3 " ).onClick(()=>{
insertFlight()
})
And you dont need export for your function since its on the same page aswel as the event as $w don’t need to be there.
This :
export
function insertFlight(event, $w)
Should be :
function insertFlight()

Kind regards,
Kristof.

The change from $w( " #button3 " ).onClick(insertFlight) to $w( " #button3 " ).onClick(()=>{
insertFlight()
})

Is that a best practice change? Because it works the way I have it (I guess it is a habit from my VB coding days). But if it will bite me in the butt down the road I will adjust it.

I made the other adjustments you suggested.

Thanks for your help, I am off and running now.