Reset Form Item in JavaScript

Slaimus

Senior member
Sep 24, 2000
985
0
76
The form has a .reset() which will reset it to the original values for all items, but I want only a single item in the form to be reset. Is there a way to do that?

For example, the form loads with the item's value = 20, user changes it to 10. I need JavaScript to change that back to a 20, and without additional server side code.
 

ahurtt

Diamond Member
Feb 1, 2001
4,283
0
0
Yes, just explicitly set the value of the field to what you want it to be.
 

Slaimus

Senior member
Sep 24, 2000
985
0
76
Originally posted by: ahurtt
Yes, just explicitly set the value of the field to what you want it to be.

But the Javascript does not know what it should be. The server could return the form item as 40 or 50 or 60. The Javascript only knows what is in the item currently, not what it was before the user changed it.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Store the original value in a hidden field and retrieve it when resetting?

I don't remember all my javascript, is there support for dictionaries? What I'm thinking, as a more elegant solution, is that when the form finishes loading you use javascript to iterate over all the inputs in the form and store their values in a dictionary with the input name as the key. Then, when you want to reset a given input, just look up the original value in the dictionary and set it.