@Alwin, it seems like all you're doing is abstracting my original suggestion of storing the original value in the data object for the corresponding input into another method that then uses the data method (e.g. the holdData function has my original suggestion as its only content). I'm not seeing from your example where you're using the holdData/retrieveData methods as they are part of var form, instead you use $("#name").val( $(this).data('value') ) which appears to just be accessing the data element on the input (not sure of the context of 'this' in the data call), or am I missing something?
As Brad indicated, he not only needs to restore the value, but also any other attributes that may have changed, so you'd have to store more than just the value. @donb Cloning the form and replacing it wouldn't reset individual fields (the OP asked about restoring a specific field). You could extract nodes out of the clone I suppose, but it seems less friendly than just using the data option. On Mar 10, 3:03 pm, Alwin Pacheco <kesler.al...@gmail.com> wrote: > Try to use something like this... > > var form = function() { > var self = this; > > this.holdData = function() { > $(':input').each(function(i, field) { > $(this).data('value', $(this).val()) > }); > return self; > }; > this.retrieveData = function() { > $(':input').each(function(i, field) { > $(this).val($(this).data('value')).removeData('value') > }); > return self; > }; > > }; > > This way you save the input's value in the object's data holder.... > if you need to set/retrieve an individual value you can always do the > following > > $("#name").val( $(this).data('value') ) // removing the data is > optional, but recommended to avoid old data conflict... I use this > code a lot and it works as a swiss knife > > Regards, > Alwin