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 664163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:34:10+00:00 2026-05-13T23:34:10+00:00

I want to have a feature to submit several forms on a page when

  • 0

I want to have a feature to submit several forms on a page when the user leaves the page. There is this “do you wanna save?” question and my code so far is like this:

function checkForChanges( ) {
  if (window.formform1Changed == true) {
    if (window.asked == false) {
      window.asked=true;
      doSave = confirm("Wanna save? Click OK")
    }
    if (window.doSaveForms || doSave) {
      window.doSaveForms = true;
      document.forms.form1.submit();
    }
  }
  if (window.formform2Changed == true) {
    if (window.asked == false) {
      window.asked=true;
      doSave = confirm("Wanna save? Click OK.")
    }
    if (window.doSaveForms || doSave) {
      window.doSaveForms = true;
      document.forms.form2.submit();
    }
  }
}

It may seem a little bit of overkill but it is generated automatically by our template engine and may be extended to more forms.

The body tag:

<body
 onLoad="init();
         window.formform1Changed=false;
         window.asked=false;
         window.doSaveForms=false;
         window.formform2Changed=false;"
 onbeforeunload="checkForChanges();">

And interesting part of one of the forms (the other one looks identically:

<input value="xyz" id="la" onchange="window.formform1Changed=true;" />
<input name="save" onclick="window.formform2Changed=false; window.formform1Changed=false;" type="submit" value="save" />

Now to the problem:
If I change values in both forms and navigate away from the page, the question from the first form pops up. I click OK, the form is saved but the form1.submit() triggers a new onBeforeUnload event which breaks the whole logic of my idea.

The question now would be if there is a way to submit all forms on a page when only asking one time when the user navigates away?

Any help is highly appreciated!

Thanks.

  • 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-13T23:34:11+00:00Added an answer on May 13, 2026 at 11:34 pm

    Form submissions requires post-back, once you submit the first form, your page is redirected to the “action” of that form and you will lose the information in the rest of the forms you have.

    Having multiple forms on the page is not the best idea, however, if you absolutely have to have them, the way to save all of them would be to replace full post-back with an AJAX call to a web-service (or a stand-alone page, that accepts query string parameters, though it’s not as secure or flexible way). That way you can submit each form over the AJAX call without page redirecting.

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

Sidebar

Related Questions

I've got a UITableView and I want to have a 'next 25' feature like
I've got a trunk setup where all my production code goes. Then I have
I have a mediawiki installation that I've customized with some of my own extensions.
Forgive me if this is in the wrong place, but I figured a few
I am about to develop a Windows service in C#. This service needs to
I want to control global variables (or globally scoped variables) in a way that
The URL below, the first content in the chosen answer describes JSP hiding. Hidden
I am currently in the process of building a native Google Reader iPhone application
My entity name is "Contact" and my table name is "Contact". However, the default
I'm looking to port my working Android XML parser to Blackberry, but the latter's

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.