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

  • SEARCH
  • Home
  • 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 8632385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:20:42+00:00 2026-06-12T09:20:42+00:00

I’ve got a page that should warn if the user tries to leave the

  • 0

I’ve got a page that should warn if the user tries to leave the page having unsaved data. This dialog means “You have unsaved data. Do you want to conitnue?”

enter image description here

The problem is that the form values go blank when the user clicks a link to move on and is presented with the dialog. I want to form values to stay in place so that the user actually can choose not to continue and then still have left what was entered to the form.

The way the code is now is that it keeps a flag for whether the form has dirty data and that is a hidden variable:

<input type="hidden" name="saveStatus" value="<%=saveStatus%>" />

Touching the form sets this hidden variables with onclickand onkeypressed.

On the server I’ve got some logic that checks whether data is dirty:

public boolean returnToUnsavedData(ISessionHandler sessionHandler,
        Action action) {
    String saveStatus = sessionHandler.getRequestParameter("saveStatus");

    if (saveStatus != null && !saveStatus.trim().equals("")) {
        setHasUnsavedData(true);
    } else {
        setHasUnsavedData(false);
    }

    if (hasUnsavedData()) {
        if (!"menuHasUnsavedDataOk".equalsIgnoreCase(action
                .getActionCommand())
                && !action.getActionName().equals("Administrera")) {
            ResourceBundle messages = ResourceBundle.getBundle("messages");
            UserMessage um;
            if (action.getActionCommand().equals("fastsearch")) {

                um = new ExtendedUserMessage(
                        messages.getString("PV24"), UserMessage.TYPE_WARNING,
                        "Varning", action.getActionName(),
                        action.getActionCommand(), sessionHandler.getRequest().getParameter("fastsearch"));
            } else {
             um = new ExtendedUserMessage(
                    messages.getString("PV24"), UserMessage.TYPE_WARNING,
                    "Varning", action.getActionName(),
                    action.getActionCommand());
            }
            action.addUserMessage(um);
            action.setReturnPage(action.getCurrPage());
            setLatestActionTarget(action.getActionTarget());
            return true;
        } else {
            setHasUnsavedData(false);
        }
    }

    return false;
}

I suppose this is where I could check serverside for the variables and repopulate everything and then use a technique like above with the hidden variable to keep form values.

Do you think that this idea will work or can you present alternative solutions?

  • 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-06-12T09:20:43+00:00Added an answer on June 12, 2026 at 9:20 am

    I don’t think you need server-side involvement here, you can achieve this by using just javascript:

    <input type="hidden" id="saveStatus" name="saveStatus" value="<%= saveStatus %>"/>
    

    Register an observer before the page gets unloaded and check your saveStatus variable in there:

    window.onbeforeunload = function() { 
        if (document.getElementById('saveStatus').value) {
            return 'You have unsaved changes, are you sure you want to leave the page?'); 
        }
    };
    

    However, by using this you will not have your own ‘custom’ confirmation screen, the browser’s built in confirmation will be used (similar to stack-overflow’s).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I know there's a lot of other questions out there that deal with this
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.