OK, don't return
true
or
false
, return some useful information on validation failure.
For example, return your inner HTML instead or a class combining inner HTML text and
className
. It will help you to avoid repeated assignment if every "
if
" block, all those repeated
getElementById
, etc. The principle is called Don't Repeat Yourself (D.R.Y.,
http://en.wikipedia.org/wiki/DRY[
^]), one of the most basic and important. As a result, your code will be shorter and of much better supportability.
The properties of the elements showing
innerHTML
with the style
className
will be assigned only once in some function calling your function
Validate
.
That's it.