Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:54:51+00:00 2026-05-23T00:54:51+00:00

How do I let users know that there are changes left to be saved

  • 0

How do I let users know that “there are changes left to be saved on the form if they try to close the browser window?”
I have a form with couple of fields, Now if the user changes some of the fields and clicks on Close button on the browser window, my script should alert him of unsaved changes. How do I implement this? I have put in basic form validation but can’t seem to think of a solution for window.close() event. Any sample links would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:54:51+00:00Added an answer on May 23, 2026 at 12:54 am

    Well you could use the body onbeforeunload or onunload.

    <body onBeforeUnload="return(confirm('unsaved stuff'))">
    

    Never used a return to stop a page unload before but it should work.

    Update:

    In the header of the web page to make it a global var:

    <script type="text/javascript">
    var formData = [];
    function saveForm(){
        var data = [];
        for(var index = 1; index <= 3; index++){
            data [index - 1] = document.getElementById("textfield_" + index).value;
        }
        return(data);
    }
    
    function unsavedData(){
        var newFormData = saveForm();
        for(var index = 0; index < 2; index++){
            if(formData[index] != newFormData[index]){
                return(confirm("Unsaved data, do you really want to exit?"));
            }
        }
        return(true);
    }
    </script>
    

    In the body(of course):

    <body onBeforeUnload="return(unsavedData())">
    ...
    <form ... onSubmit="formData = saveForm()">
    <input type="text" id="textfield_1">
    <input type="text" id="textfield_2">
    <input type="text" id="textfield_3">
    /*form submit button*/
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me state first: I know that any user that wants to run a
We let users create ad-hoc queries in our website. We would like to have
I want to let users specify a date that may or may not include
We have a web application that is based around a form that gets passed
before I ask my question I wanted to let everybody know that I appreciate
If I have a PHP application which allows users to make changes to documents,
Let's say I have a javascript method that takes a little to long to
Let's say I have an object that is fairly complex. Since it is so
Let's say I have a Huuge database onto a server that works with a
Before I ask my question, let me just say that I know very little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.