Hi All,
Please, if this is not the group for this, let me know and I'll post it to where it may get answered
Also please excuse the relative length of this post as I needed to get the information across.
I'm using Sub procedures written in vbscript to try an catch input errors client-side. I have a portion of it working but am
having a devil of time trying to complete it.
**the following "Call code" is on the page default.asp, a basic data entry page with 6 text boxes (4 required) and 2 select
boxes (1 required).
**of the 4 required text boxes only 1 has to be a minimum length of 7 and each character in it must be numeric. The other 3 have
no other restrictions.
**the Sub procedures being called are on the include file ValidatorClient.asp
**Each Call of WriteFormFieldTextRequired works, but.....
**Whenever I try to Call FieldMinLength (even by itself) the page reacts as if this entire Call sequence isn't there. Even the
Call of WriteFormFieldTextRequired does not work; i.e. pop up an alert box.
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Call WriteFormHeader("Form1Validator")
Call WriteFormFieldTextRequired("txtStudentIDNumber", "Student ID Number")
'---------------------------------------------------------------------------
'when this is uncommented out this whole call group seems as if it has not been called, just blown by.
'Call FieldMinLength("txtStudentIDNumber", 7, "Student ID Number")
'---------------------------------------------------------------------------
Call WriteFormFieldTextRequired("txtStudentFirstName", "First Name")
Call WriteFormFieldTextRequired("txtStudentLastName", "Last Name")
Call WriteFormFieldTextRequired("selResidenceHall", "Residence Hall")
Call WriteFormFieldTextRequired("txtRoomNumber", "Room Number")
Call WriteFormFooter()
'and fyi the form tag
<form action="default.asp" method="post" id="PreReg" name="PreReg" onSubmit="return Form1Validator(this)">
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
**the include page ValidatorClient.asp as is:
<%
'----------------------------------------
' Accepts strFunctionName as string - Name of javascript function
'----------------------------------------
Sub WriteFormHeader(ByVal strFunctionName)
With Response
.Write(" <scr" & "ipt 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
'----------------------------------------
' Accepts strMinLengthFieldName as string -Name of the field to validate
' Accepts intMinLength as integer - minimum length strMinLengthFieldName has to be
' Accepts strMinLengthDisplayName 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 a minimum length
' is not attained.
'----------------------------------------
Sub FieldMinLength(ByVal strMinLengthFieldName, ByVal intMinLength, ByVal strMinLengthDisplayName)
With Response
.Write(" // " & strMinLengthDisplayName & " - Start" & vbCrLf)
'**I've tried the following both with and without the CInt**
.Write(" if (theForm." & strMinLengthFieldName & ".value.length < " & CInt(intMinLength) & ")") & vbCrLf
.Write(" {" & vbCrLf)
.Write(" alert(""The \""" & strMinLengthDisplayName & "\"" field is not long enough."");") & vbCrLf
.Write(" theForm." & strMinLengthFieldName & ".focus();") & vbCrLf
.Write(" return (false);") & vbCrLf
.Write(" // " & strMinLengthDisplayName & " - End") & vbCrLf
End With
End Sub
Sub WriteFormFooter()
With Response
.Write(" }") & vbCrLf
.Write(" // -->") & vbCrLf
.Write(" </scr" & "ipt>")
End With
End Sub
%>
Any questions pleae so not hesitate to ask.
Thank you for your time and in advance for your help.
gdr
--
Gary D. Rezek
University Networking Services
South Dakota State University