Javascript: Update record field when user leaves page

I have customers who can sign up for available timeslots (object) through a form embedded on my webpage.

They can see all the available time slots in a table view.

Right now I have no way of preventing that two people might access the same timeslot and signing up at the same time.

Nic from support suggested using javascript to make an AJAX request to the record if the user leaves the page.

Im not very good with javascript, but after some googling I found that the $( window ).unload(function() might be what I'm looking for.

I do however not know how to use this to update fields in knack.


Does anyone have a suggestion for how to solve this?