Question

I want to show a confirmation message on click of cancel button and then redirect to another page. But the confirmation message should come only if any change has been done on the page.

Please can anyone help on this. Is it possible to achieve this at client side or at server side without comparing data ?

Thanks in advance.

Was it helpful?

Solution

I'm guessing you could have a scenario where:

A form is populated with values and each form item that you are tracking for changes also has a corresponding hidden field.

If the user clicks submit = great, but if the user clicks cancel you want to loop through each form item, comparing it to it's original value stored in the hidden field. If a change is detected you want to show a pop-up window informing the user that if they cancel their changes will lost - or something like that.

You can do all this on the client. JQuery, or Knockout (which I would use) or Backbone (I don't know this one tbh) should all provide a neat way to achieve this.

If you can't have hidden fields you might want to send the new values to the server in an Ajax post, get the server to pull the original values, compare and send back an appropriate response to the client. I'm sure there are other ways too*.

edit: like pop the original values in an array via Javascript, then compare them. Anyway, I'm sure you get the idea :)

OTHER TIPS

This could be accomplished using jquery you would need to compare data since you want the message to come up when the cancel button is clicked.

jquery reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top