JavaScript : Advanced Form Management
Contents ]
Mikael Le Moal

Multiple Validations

When a form content is submitted, there is often a certain time lapse during which the visitor does not know if the data have been validated. There can be various reasons for this: complex processing, overloaded network, etc. And sometimes the user reactivates the submission, thinking that nothing has happened. The function desactiveForm will deal with this problem:

6: function desactiveForm(f) {
7:    if (document.all || document.getElementById) {
8:       for (i = 0; i < f.length; i++) {
9:          var t = f.elements[i];
10:          if (t.type.toLowerCase() == "submit" || t.type.toLowerCase() == "reset")
11:             t.disabled = true;
12:          }
13:    }
14:    return true;
15: }

To prevent the user from repeating data submission, the buttons Submit and Reset are deactivated (lines 10 and 11). This function looks through all the controls which the form contains to locate these two buttons and deactivate them.



  1   2   3   4   5