0

I am working on a web application which contains forms. I want to auto submit the forms if the user started to complete it but left and then got disconnected from his session.

I already have a JS alert after 15 minutes asking is user wants to submit the form or not. Then if the user doesn't answer, I want to auto submit. But the problem is that an alert box stops the code running. I tried with the line "setTimeout(function(){ submitform() }, 60000);" to auto submit after 1 minute but it obviously doesn't work.

function submitform(){             
         document.forms["form_pat_bvl"].submit();
       }
               
function confirmAction() {
        let confirmAction = confirm("Would you like to submit ?");
           if (confirmAction) {
                submitform();
        }
                setTimeout(function(){ submitform() }, 60000);
      }

I also tried with "<META HTTP-EQUIV="Refresh" CONTENT="60;url=../servlet/mypage">" but it only works for the doGet method wheras my servlet uses the doPost method.

I don't know if my ideas are good, I have been asked to do this way by asking user first if he wants to submit and then submit for him if he doesn't answer... but I really don't know how to save his form if he's inactive after an alert.

Thank you in advance !

Tinks
  • 1
  • 1
  • You need to NOT use alert since it is blocking as you found out. Instead show a dialog that is non-blocking – mplungjan Jun 04 '21 at 14:16
  • 1
    The actual way to do it, is to ajax the content after a few seconds on a regular basis – mplungjan Jun 04 '21 at 14:16
  • As @mplungjan mentioned, you might use a dialog, take a look here https://stackoverflow.com/questions/10416798/is-it-possible-to-close-confirm-box-after-a-time-interval – axtck Jun 04 '21 at 14:21
  • https://stackoverflow.com/questions/2101259/get-text-from-field-on-keyup-but-with-delay-for-further-typing – mplungjan Jun 04 '21 at 14:22

0 Answers0