Share This!

Friday, June 3, 2016

MVC - JQuery Prompt User to Save Modified Page.

I had users clicking off my page while doing data entry, and I needed to make sure they didn't forget to save their modifications.


Here is a simple example HTML page that implements a rudimentary check.  This is not tested for all data types.   Enjoy.



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<html xmlns="">


    <title> Safe Exit Test </title>

    <script src=""></script>




    <form action="">

        <input type="number" name="value" />

        <input type="submit" name="commit" />



    <a href="">209software</a>



        $(document).ready(function () {

            formmodified = 0;

            $('form *').change(function () {

                formmodified = 1;


            window.onbeforeunload = confirmExit;

            function confirmExit() {

                if (formmodified == 1) {

                    return "New information not saved. Do you wish to leave the page?";



            $("input[name='commit']").click(function () {

                formmodified = 0;







No comments:

Post a Comment

Contact Us


Email *

Message *