SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 219 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

parentNode.getElementsByTagName('span')[0];
}
span.innerHTML = validator.VALIDATIONS[fieldname]["error"];
} else {
// the regular expression *did* match
// is there a span.error already?
spans = fld.parentNode.getElementsByTagName('span');
if (spans.length == 0) {
// there is no error span, so do nothing
} else {
// remove the error span
span = fld.parentNode.getElementsByTagName('span')[0];
span.parentNode.removeChild(span);
// and remove class="error" on the field's label, if it has it
lbl = fld.parentNode.getElementsByTagName('label')[0];
if (lbl.className == 'error') {
lbl.className = lbl.className.replace(/\berror\b/,'');
}
}
}
}
}
The bold sections are those that have changed. The code to display an error message
simply, instead of assuming that a span exists, checks to see whether it does exist (by looking
for spans that are siblings of the text field). If it does not, the code creates the span with
createElement() and inserts it into the document. Similarly, the code to remove the error
message checks whether a span exists; if it does, the span is removed.
As a small extra wrinkle, the remove code also removes class="error" from the label if the
server code put it there.
Preventing the Form Being Submitted
Another usability enhancement is to prevent the form from being submitted if there are errors
present. It??™s generally good practice to stop the user from doing something if you know it??™s not
going to work.


Pages:
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6