views:

338

answers:

4

Hello everybody,

I have multi-step form and user can navigate to any page to modify or add information. There is a menu that shows progress and steps user completed. This menu allows to navigate to any step user completed or going to complete.

Inspite of big button "Save and Continue" some users click this menu to navigate further. I have to check - if values have changed in a form and ask: "Save changes? Yes/No".

What is the best way (with minimum client-side javascript code) you suggest me to check if form values have changed.

Thank you in advance!

Edited a bit later:

I forgot to tell that multistep form uses postback between steps.

+1  A: 

The jQuery "Dirty Form" plugin may help you out here:

http://plugins.jquery.com/project/dirtyform

Paddy
Oh thank you very much. It looks promising :) I'll give a try
Andrew Florko
Plugin seems to be not very flexible, so I had to change the code a bit. But it saved me lots of time anyway. Thank you for your answer :)
Andrew Florko
It seems to be buggish also )
Andrew Florko
Not really used it - had a quick look at a while ago, sorry if it's problematic.
Paddy
A: 

The jQuery Form Wizard plugin should be useful in this case.

See Demo Here

Sarfraz
Nice plugin. Sorry, I forgot to tell my multi-step form uses postback between steps
Andrew Florko
A: 

This is not entirely easy without JQuery because the onchange event for forms is not consistently supported across browsers.

I'd say if you can, use one of the jQuery plugins presented in the other answers.

If jQuery is out of the question, consider adding a simple onchange='if (this.value != this.defaultValue) dirty_flag = true;' to each input element. If you want a clean approach, do this in a <script> section:

document.getElementById("formid").onchange = 
 function() { if (this.value ....) }
Pekka
Thank you for your response, but that is exactly i am afraid of :) I'll take a look at: http://plugins.jquery.com/project/dirtyform
Andrew Florko
A: 

Since you mentioned you're posting back between steps, I'd have a hidden field that stores what the next step is. By default this would be the next step of the form. The "Save and Continue" button just submits the form.

Each menu entry then would then set the value of this hidden form to the appropriate step, and then it would submit the form. Something like:

<script type="text/javascript">
function goToStep(step) {
document.getElementById("hiddenFieldID").value = step;
document.getElementById("formID").submit();
}
</script>

<ul id="menu">
  <li><a href="javascript:goToStep(1);">Step 1</a></li>
  <li><a href="javascript:goToStep(2);">Step 2</a></li>
  etc...
</ul>
Bryan Ross
Thank you, but the question was how to check if form is dirty )
Andrew Florko