dimanche 4 novembre 2018

Functions second argument being passed as a conditional?

The functions task is to set and clear help messages in the form field using built in css classes. My question is why do I need to validate the helpText argument within the function to be non equative to null? The argument is linked by the id it shares with the span tag so why is validation necessary?

<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;    
}


}

Aucun commentaire:

Enregistrer un commentaire