I forgot to paste in the div ID into the script in the example above. I've fixed that. Please update the script on the bottom of the page and see if that helps.
You can't save the values into the session "before" someone leaves the page. Session variables are stored on the server with php, so they have to be saved after a form post on the action page of the form.
You can add code to save the form element values into the session on the page specified as the form action page.