views:

41

answers:

3

I have a form with a dynamically-generated group of fields - backend is php/mySQL, and the form is created by reading in data from a table and creating a group of fields for each record. The form has a bit of javascript onSubmit that confirms whether the user really wants to save their changes, but I'm having trouble reverting to the original values if they say that they don't want to save. Reloading the page from the database is not an option.

A: 

If a round trip back to the server is out of the question, I'd say the only way to deal with this is to keep the original values of the form fields in javascript (variables, array, whatever makes the most sense) and use these to repopulate the form fields.

carnold
A: 

On the initial loading of the form store the values in "hidden" input fields. Use the values of these hidden fields when you cancel the form.

del.ave
+4  A: 

Unless you're doing something wildly unconventional, try:

<input type="reset" value="Cancel" />

Or if you need to do it in javascript:

document.yourform.reset()
Juliet
Thank you! I knew there had to be an easier way than saving duplicate "oldValue" fields for every single field that could be changed (which in this case can be several hundred.) For some reason I thought reset would set everything to blank.
EmmyS