* submitting a form with invalid data.
*/
+function update(obj, slot, value) {
+ /* Update an object slot only if we're gping to change its value. */
+ if (obj[slot] !== value) obj[slot] = value;
+}
+
function check() {
/* Check through the various forms to make sure they're filled in OK. If
- * not, set the `F-whinge' elements, and disable `F-submit'.
- */
+ * not, set the `F-whinge' elements, and disable `F-submit'.
+ */
var f, form, whinge;
for (f in FORMS) {
we = elt(f + '-whinge');
sb = elt(f + '-submit');
whinge = form.check();
- if (sb !== null) sb.disabled = (whinge !== null);
+ if (sb !== null) update(sb, 'disabled', whinge !== null);
if (we !== null) {
- we.textContent = whinge || 'OK';
- we.className = whinge === null ? 'whinge' : 'whinge wrong';
+ update(we, 'textContent', whinge || 'OK');
+ update(we, 'className', whinge === null ? 'whinge' : 'whinge wrong');
}
}