Why is it necessary to validate the helpText argument within the function to be non-equative to null when its ID is linked with the span tag? The functions task is to set and clear help messages in the form field using built-in CSS classes.
<input id="phone" name="phone" type="text" size="12" onblur="validateNonEmpty"(this, document.getElementById('phone_help'))" />
<span id="phone_help" class="help"></span>
function validateNonEmpty(inputField, helpText) {
// See if the input value contains any text
if (inputField.value.length == 0) {
// The data is invalid, so set the help message
if (helpText != null)
helpText.innerHTML = "Please enter a value.";
return false;
}
else {
// The data is OK, so clear the help message
if (helpText != null)
helpText.innerHTML = "";
return true;
}
}