Automatic Javascript Form Validation
This is a simple script I wrote to automatically create the code necessary to validate form fields using Javascript. The code makes it easy to create validation on your forms without having to manually code the Javascript each time.
The ASP Code
<%
Sub javascript_validate(strFields, strFunctionName)
Dim strValidate
If strFunctionName = "" Then strFunctionName = "validate"
If strFields <> "" Then
%>
<%
End If
End Sub
%>
Sample Form Usage
<%
'Usage: javascript_validate [list of varables and errors if blank], [name of validation function]
javascript_validate "fullName:Please enter your full name:age:You must enter your" & _
"age.:form.gender.selectedIndex == 0:Please choose a gender.", "validateForm"
%>
In this example, if the user clicks Submit without filling out some or all of the required fields, they will get a message like this:



