Input validation that uses HTML field attributes in R5

This input validation takes advantage of the HTML tab (the last one) in the R5 field properties in two ways.

First, it uses the other section to assign an attribute to the field(s) in question.

Second, it uses the title section to display a meaningful name for the field(s) in question.

Scenario: I have five text fields on a web form. Three of them are mandatory and require validation for non-blank entries.

For the mandatory fields MF1, Mf2 & MF3:
1. Assign an attribute such as FT=M (Field Type=Mandatory) in the other section of the HTML field tab.
2. Enter the descriptive name of each field in the title section of the same tab. This will be used in the message displayed to the user. Example: for MF1 the descriptive tile is: Customer Creation Date

 Code (in the JS Header of the form):
function validate()
var f=document.forms[0]
//Loop through the elements of the form looking for fields with name=text AND Tagged with the attribute FT=M
for (i=0;i<f.length;i++)

//If element if a text field AND is mandatory (i.e. FT=M) AND has been left blank, capture it.
if(f.elements[i].type=="text" && f.elements[i].FT=="M" && f.elements[i].value=="")
alert("You must enter " + f.elements[i].title)
//Return user to offending field
//terminate function
return false
//End of Code

The above code works equally well for a ComboBox. The field type to look for is "select-one" instead of "text."

This was first published in August 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.