开发者

Looking for most efficient way to revert form values to original values on cancel

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 t开发者_如何学Pythonhe original values if they say that they don't want to save. Reloading the page from the database is not an option.


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()


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜