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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:53:09+00:00 2026-05-16T01:53:09+00:00

I have a form broken into 5 steps. Currently if you refresh/exit/close etc on

  • 0

I have a form broken into 5 steps. Currently if you refresh/exit/close etc on steps 2-4 it returns a message via window.onbeforeunload no issues there.

window.onbeforeunload = function () {
            if ( $("#step1").is(":visible") || $("#step2").is(":visible") || $("#step3").is(":visible") ) {
                return 'Using the browsers back, refresh or close button will cause you to lose all form data. Please use the Next and Back buttons on the form.';
            }
        }

Now I need to add the same or similar type of behavior on step0 (first step) if checkbox “A” is checked and checkbox “B” isn’t. This works, but not combined with another .onbeforeunload function

window.onbeforeunload = function () {
            if ( $("#A").is(":checked") && $("#B").is(":not(:checked)") ) {
                return 'Message here. Do you wish to continue?';
            }
        }

How can I chain these two together? using an if, else statement doesn’t seem to work.

  • 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-16T01:53:10+00:00Added an answer on May 16, 2026 at 1:53 am

    You can combine them in one function like this:

    window.onbeforeunload = function () {
      if ( $("#A").is(":checked") && !$("#B").is(":checked") ) {
          return 'Message here. Do you wish to continue?';
      }
      if ( $("#step1, #step2, #step3").filter(":visible").length) {
          return 'Using the browsers back, refresh or close button will cause you to lose all form data. Please use the Next and Back buttons on the form.';
      }
    }
    

    I simplified your other selector to grab all elements, .filter() only :visible ones and see if there are any (.length > 0), this is just an easier-to-maintain way of going about it.

    Also you may want to add an additional check to the first if, ensure you’re on that step, like this:

    if ($('#step0').is(':visible') && $("#A").is(":checked") && !$("#B").is(":checked") ) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have subclassed Form to include some extra functionality, which boils down to a
I have a form with some radio buttons that are disabled by default. When
I have a form with many input fields. When I catch the submit form
I have a form in which people will be entering dollar values. Possible inputs:
I have a form element that contains multiple lines of inputs. Think of each
I have a form that contains a GridView control which is databound to an

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.