Standard JQUERY method to store the original value of a form field?
Is there a standard way in JQUERY (when preparing the document) to store the original values of the form fields on the page to check (later) if the fields were actually changed or not?
I will usually do something like this:
var NameField = $("INPUT[name='NameField']");
//Record the original value.
NameField.OriginalVal = NameField.val();
It's simple enough, but I'm wondering if there is a "standard" way to do this.
EDIT
One additional requirement I forgot is that it should work for all types of form fields, including select and textareas.
a source to share
The default value (that is, the value specified in the source code using the attribute value
) is automatically available as a property defaultValue
.
alert($("#myInput").defaultValue);
It seems to be part of the JS specification since 1.0, so it's safe to use. ( Link , German only sorry)
a source to share