First of all, it's very important that you NOT rely on your ID #'s being nice an sequential. Someday one will get corrupted or it will be a duplicate or whatever and you will have to delete it and there will be a hole. It's very important that you design your web site to handle ID #'s not being sequential.
Either (A) create the record when they load the page and have an ID# that may or may not actually get used, or (😎 give them a page where they can create all the lines of the report but don't actually create the record (and commit an ID# to this report) until they submit the page. Either way is perfectly fine. If you try to create a web site that relies on perfection where nothing ever goes wrong (the kinds of things that end up causing a skip in sequential ID#'s), then your web site is just a big house of cards waiting to collapse.
As for the technical question, have a javascript variable that keeps a record of whether or not the page has been saved. (This is called recording state). The variable might be called "page_has_been_edited" or something like that. When the page first loads, the variable should be set to zero.
Whenever anyone adds a line or makes a change of any kind, then set the variable to "1". Whenever anyone clicks save and the save was successful, then set it to "0".
Then use a javascript body on_unload event to call a function that checks to see if "page_has_been_edited". If the variable is equal to 1, then alert that they should save the page.