Thanks for the help on the other question. I missed the part about
reverting the value.

Actually I don't think that I need to explicitly store the value. If I
store the value of  $(this) as shown I can later retrieve the value
for a specific field by e.g., calling ...

$(origFormData['age']).val()

..., but I need to explain my requirement in more detail.

Restoring the input field's value is only one part of the problem.
There are a number of other attributes that might need to be restored.
Depending on how the backend code originally displays the form, a
field can start out enabled or disabled. It can start out with a
special class assignment. These attributes can dynamically change as
the form is used. Therefore resetting a field may involve more than
restoring the field's original value.

What I was hoping I could do was store an jQuery object that contained
all of the information about the field and somehow (magically) use
that to overwrite the current representation of that same field.

Am I dreaming?

Thinking of other ways to solve this problem, is there a way with
jQuery to get the full html of an input element? The .html() method
doesn't do it.

On Mar 10, 12:02 pm, 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