Rob,

  Thanks a ton.  I was able to code up what I needed with your
advice.  Here's what I did, in case someone else out there needs to do
something like this in the future.

    Russ

/**
 * Set all the default values of a form to whatever is there now,
effectively updating the reset
 * button to restore the form to the current state (which might be
different than the state the
 * form was in when the page was loaded).
 *
 * @param formID  Form id (starting with "#") to update the default
values of
 */
function resetFormToNewValues(formID)
{
    $(formID).find(':input').each(function ()
    {
        if ($(this).is(':text'))
        {
            // TODO - Not tested for textareas
            $(this).attr("defaultValue", $(this).attr("value"));
        }
        else if ($(this).is(':checkbox, :radio'))
        {
            $(this).attr("defaultChecked", $(this).attr("checked"));
        }
        else if ($(this).is('select'))
        {
            $(this).find("option:selected"      ).attr
("defaultSelected", true);
            $(this).find("option:not(:selected)").attr
("defaultSelected", false);
        }
        else if ($(this).is(':password, :file'))
        {
            // TODO - This is untested
            $(this).attr("defaultValue", "");
        }
    });
}

Reply via email to