simply saying var ThisVar = whatever;
makes it "global" so in your code, it would be like <script type="text/javascript"> var FormData = {}; $(document).ready(function(){ $(":input").each(function() { FormData[this.id] = $(this).val(); }); }); function resetField(id) { if (FormData[id] != null) { $("#" + id).val(FormData[id]); } } </script> On Mar 10, 11:38 am, Brad <nrmlcrpt...@gmail.com> wrote: > This is really a javascript question, but will use jQuery. > > When a page first displays I would like to save a bunch of data about > a form. For example the IDs of all of the inputs and how they are > originally defined. Depending on user actions I may need to restore > individual form fields to their original state. I don't need to reset > the entire form. I know how to use jQuery to select the original form > elements, but am struggling with how to store them into an object that > I can refer to and retrieve individual input data for later. > > // a global object that stores form data > What goes here? How do I make it global and persistent? > > // a function that resets an field to its original state > function resetField(id) { > // refers to the global object, but how? > > } > > $(document).ready(function(){ > // save initial form configuration > how called? > > });