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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:17:34+00:00 2026-06-02T20:17:34+00:00

I have forms with about 100 input fields each (textbox, textarea, radio, checkbox, file,

  • 0

I have forms with about 100 input fields each (textbox, textarea, radio, checkbox, file, etc).
When the user leaves the page I need to know if some field has been modified in order to run an autosave routine.

1.- Set form_has_been_modified when any field change:

var form_has_been_modified = 0;
$("form[id^='my_form']").each(function(){
    $(":input", this).live("change", function() {
        form_has_been_modified = 1;
    });
});

2.- Warn user if some field was changed:

window.onbeforeunload = function (e) {
    if ( ! form_has_been_modified){
        return;
    }

    var message = "This page is asking you to confirm that you want to leave - data you have entered may not be saved.";

    var e = e || window.event;

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = message;
    }

    // For Safari
    return message;
};

Questions:

a.- Could this code (part 1) make too much slow the browser’s user?

b.- The previous code is working very well. But in textbox/textarea input types the change event only occur when elements loses focus. So for example this code does not protect against reload page actions. There exists another better handler instead change to solve this deficiency?

  • 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-02T20:17:35+00:00Added an answer on June 2, 2026 at 8:17 pm

    I would use keyup, which might be close enough, although you could get some false positives.

    Also, with .on() you can replace your .each() loop with a single call (and .live() had been deprecated in 1.7+ anyway):

    $("form[id^='my_form']").on("change keyup", ":input", function() {
         form_has_been_modified = 1;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have previously written user interfaces using .NET and Windows Forms. I'm about to
I have a form, that has about 10 text entries (user, address, email etc;)
I have a few large forms that I need to provide visual cues about
I have an order form with about 30 text fields that contain numerical values.
I have several ASP:TextBox controls on a form (about 20). When the form loads,
I have a form that takes in a number of fields about a camera's
I have an upload form that takes a user about 30 min. to complete.
I have about 50 RadioButtonList on a form with a checkbox next to them.
In a Windows Forms C# app, I have a textbox where users paste log
I have a table containing user input which needs to be optimized. I have

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.