I'm thinking that

$("form input").each(function() { $(this).val(origFormData[$(this).attr
("id")]); });

should step over each input field in a form and conjure up values from
the origFormData object based on the id of the current element
conjuring a value.

But the state-saving code should be more along the lines of

                $(":input").each(function(){
                        origFormData[$(this).attr("id")] = $(this).val
(); // Might not work with checkboxen
                });

to get the value of the field and keep the origFormData based on the
ID of the field.

Hope it helps!
NNeko

On Mar 10, 10:36 am, 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