About This Code
Brief Description:
The JavaScript function for failNull
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
The JavaScript function for failNull follows:
Here is the failNull syntax:
if(parent.failNull(form.ProfileApprovers1,"You must specify one or more approvers for the first approval step","text")) return;
The JavaScript function for failNull follows:
function failNull ( vField, vMessage, vType) {
//this function will stop the submit if a field is null or contains all spaces
//get the field value... theValue = getFieldValue (vField, vType);
//if the field value is null, we fail and return true... if ( theValue == "" ) {
alertBox ( vField, vMessage, vType );
return ( true );
}
//remove any spaces from the value
trimField = trimBlanks( theValue );
//if the field value is all spaces, fail and return true... if ( trimField =="" ) {
alertBox ( vField, vMessage, vType );
return ( true );
}
//otherwise continue...
return ( false );
} Return either a Boolean True or False value so that we can stop the submit. If the function is True, or if a validation failed, we stop the submit, return a JavaScript alert with a specific failure message, and focus the cursor on the field that failed the validation test. The function illustrated above call three subroutines: getFieldValue, trimBlanks and alertBox. The getFieldValue function retrieves the actual value the user entered or selected in the field being tested. To further explore the getFieldValue function, we need to consider input data types and browser types.
Usage / Example