• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Reset Form Item in JavaScript

Slaimus

Senior member
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.
 
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.
 
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.
 
Back
Top