OpenNTF.org - The JavaScript failContains fu
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
The JavaScript failContains function 
Rating:
Not Rated Yet 
Contributor:
Andrew Jones 
Category:
Java 
Type:
 
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 failContains function looks like this: Here is the syntax for the failContains logic:
if (parent.failContains( form.EditProfileFormKeyOverride_1, "N", "You must select Yes to continue.", "radio") ) return;
if (parent.failContains( form.EditProfileFormKeyLabel_4, ',;:',"Labels/questions cannot contain commas, colons, or semicolons.", "text", "mult")) return;
The JavaScript failContains function looks like this:
function failContains( vField, vValue, vMessage, vType ) {
//this function will stop the submit if a field contains a specified value (or value list)
//get the field value... theValue = getFieldValue (vField, vType);
//check argument list to see if we are testing multiple characters... var count = ( failContains.arguments.length == 6 ) ? vValue.length-1 : 0; var value = ( failContains.arguments.length == 6 ) ? vValue.substring(0,1) : vValue;
//fail the submit if the field contains the value(s)... for ( i = 0; i <= count; i++) { if ( theValue.indexOf(value) > -1) {
alertBox ( vField, vMessage, vType );
return (true);
} value = ( count > 0 ) ? vValue.substring(i+1,i+2) : vValue; }
//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
 Comments

No documents found

 Add your comment!