Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    32

    Cool Unanswered: save/submit on close prompt

    Hello,
    I have created a business application and the end users have requested that I add a prompt to ask if they wish to save/submit when navigating away from a form. I'm not sure if I can do this with php or if I need to embed some javascript to accomplish this. Can anyone lead me in the right direction or suggest some references.

    Cheers
    Tim

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    PHP by it self can do nothing in this case. Web servers and browsers are stateless. They know nothing about what happened before or what will happen in the future. Once a form has been sent from a web server to a client and rendered in a browser, there is no connection between the server and the browser.

    You could use AJAX techniques to send every keypress to the server where it could be saved and in thinking about it, you could probably use javascript to save the contents of a form field into a cookie with each keypress in that field...

    Other than detecting and storing info on each keypress, I am pretty sure that there is not any "reliable" javascript/method that you can use to detect when a page is closed/navigated away from and store/submit anything in the fields after it is sitting in the fields.
    Last edited by dbmab; 03-20-07 at 11:27.

  3. #3
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    You can use the window.onunload event handler
    e.g.
    Code:
    window.onunload = myfunc();
    
    function myfunc() {
      alert("i am closing now");
    }

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Ah, it's just clicked. I reread what you are trying to achieve.
    I think dbmab could be right. What you need is a function call every time someone clicks on another link in your website to check whether the information has been posted/saved already.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •