Rather than create a global object, why not just take advantage of the
jQuery data method and store the original value with its corresponding
form element:

$(":input").each(function(){
        $(this).data('origVal',this.value)
});

On Mar 10, 11:02 am, MorningZ <morni...@gmail.com> wrote:
> You forgot an important part of the line
>
> origFormData[this.name] = $(this);
>
> and this is you need to store the value, so
>
> origFormData[this.name] = $(this).val();
>
> and on your other topic, the code was also provided to revert the
> value back to the saved value
>
> On Mar 10, 1:36 pm, Brad <nrmlcrpt...@gmail.com> wrote:
>
> > I have a need to reset individual form objects to their original
> > state. When the document loads I save the element like this:
>
> >         var origFormData = {};
>
> >         $(document).ready(function(){
>
> >                 // Save original form data for each input field
> >                 $(":input").each(function(){
> >                         origFormData[this.name] = $(this);
> >                 });
>
> >         });
>
> > For example I have a form with fields named name, age, and dept
> > selectable by $("#name"), $("#age"), and $("#dept") respectably.
>
> > How would I go about later restoring/resetting a specific field. Is
> > there a simple way to overwrite the object represented by $("#name)
> > with origFormData.name?

Reply via email to