Expand|Select|Wrap|Line Numbers
- this.formIsDirty = function (formObj)
- {
- for (var i = 0; i < formObj.elements.length; i++)
- {
- var element = formObj.elements[i];
- var type = element.type;
- if (type == "checkbox" || type == "radio")
- {
- if (element.checked != element.defaultChecked)
- {
- return true;
- }
- }
- else if (type == "hidden" || type == "password" || type == "text" ||
- type == "textarea")
- {
- if (element.value != element.defaultValue)
- {
- return true;
- }
- }
- else if (type == "select-one" || type == "select-multiple")
- {
- for (var j = 0; j < element.options.length; j++)
- {
- if (element.options[j].selected !=
- element.options[j].defaultSelected)
- {
- return true;
- }
- }
- }
- }
- return false;
- };
And I assume (if I am wrong here please correct me) that the default value/status is untouchable for updating.
This technique does not lend itself very well to a form that loads blank and is then back filled with data from an ajax call. In this scenario, it would be nice to establish a point at which the default values are set.
There is a difference between loading a form with data from the database and changing one or more of the values which have been loaded.
Is there some similar generic routine that could be used to test if one or more states/values of a form loaded from an AJAX call have been changed?