top of page
bottom of page
const form = $w('#myForm');
const pickup = $w('#pickup');
const dropoff = $w('#dropoff');
const date = $w('#date');
const time = $w('#time');
const adults = $w('#adults');
const children = $w('#children');
const luggage = $w('#luggage');
form.onSubmit((event) => {
event.preventDefault();
const formData = {
pickup: pickup.value,
dropoff: dropoff.value,
date: date.value,
time: time.value,
adults: adults.value,
children: children.value,
luggage: luggage.value
};
sendDataToAPI(formData);
});
function sendDataToAPI(formData) {
fetch('http://localhost:3000/submit', {
method: 'POST',
body: JSON.stringify(formData),
headers: { 'Content-Type': 'application/json' }
})
.then((response) => response.json())
.then((data) => {
console.log(data); // Handle response data
})
.catch((error) => {
console.error(error);
});
}