data entry validation

G

Gary D. Rezek

Hi All,
I'm trying to make an .asp include for form data entry validation. I found Ken Schaefer's site
http://www.adopenstatic.com/resources/code/UIValidation.asp
and am *just* trying to learn how to write javascript using vbscript so I don't know if
what I have for **Sub WriteFormFooter()** at the bottom of this post is correct in its syntax.
I know the input form's data is reaching these subs but when I leave an input text box blank
I do not get a pop-up telling me. So I am assuming that I have written that Sub wrong.

<%
********************
' Accepts strFunctionName as string - Name of javascript function
'----------------------------------------
Sub WriteFormHeader(ByVal strFunctionName)
With Response
.Write(" <script type=""text/javascript"">") & vbCrLf
.Write(" <!--") & vbCrLf
.Write(" function " & strFunctionName & "(theForm)" & vbCrLf)
.Write(" {") & vbCrLf
End With
End Sub ' WriteFormHeader
********************
' Accepts strFieldName as string -Name of the field to validate
' Accepts strDisplayName as string - Name of the field to be used in the
' alert message you want to pop up
' Writes javascript to pop up a javascript alert box if nothing is entered into the field
'----------------------------------------
Sub WriteFormFieldTextRequired(ByVal strFieldName, ByVal strDisplayName)
With Response
.Write(" // " & strDisplayName & " - Start" & vbCrLf)
.Write(" if (theForm." & strFieldName & ".value== """")" & vbCrLf)
.Write(" {" & vbCrLf)
.Write(" alert(""Please enter a value for the \""" & strDisplayName & "\"" field."");" & vbCrLf)
.Write(" theForm." & strFieldName & ".focus();" & vbCrLf)
.Write(" return (false);") & vbCrLf
.Write(" }") & vbCrLf
.Write(" // " & strDisplayName & " - End" & vbCrLf)
End With
End Sub
********************
Sub WriteFormFooter()
With Response
.Write(" }") & vbCrLf
.Write(" // -->") & vbCrLf
.Write( "</script>")
End With
End Sub
'-----------------------------------------
%>

I call these subs from the data entry page like so:

Call WriteFormHeader("Form1Validator")
Call WriteFormFieldTextRequired("strStudentIDNumber", "Student ID Number")
<<I have 4 other of the same type calls here>>
Call WriteFormFooter()

And the form tag reads thus:

<form action="default.asp" method="post" id="PreReg" name="PreReg" onSubmit="return Form1Validator(this)">

Would someone please help me to correct it?
Thanks in advance.

gdr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top