using vbscript to write jscript

G

Gary D. Rezek

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
 
G

Gary D. Rezek

Sorry....
After I posted it all the sudden I saw that I had forgotten a } in that
particular Sub.

..Write(" return (false);") & vbCrLf..Write(" // " & strMinLengthDisplayName & " - End") & vbCrLf
End With
End Sub


gotta stop doing this so late.
My apologies all.

gdr
--
---
Gary D. Rezek
University Networking Systems and Services
South Dakota State University

Gary D. Rezek said:
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
 
R

Roland Hall

in message
: Sorry....
: After I posted it all the sudden I saw that I had forgotten a } in that
: particular Sub.
:
: .Write(" return (false);") & vbCrLf
: >>right here<< (.Write(" }") & vbCrLf
: .Write(" // " & strMinLengthDisplayName & " - End") & vbCrLf
: End With
: End Sub
:
:
: gotta stop doing this so late.
: My apologies all.

Gary...

Don't worry about it. I'd bet if you polled the developers here and asked
if they have ever posted after trying again and again to get some piece of
code to work, and minutes after posting, solved the issue themselves. I'm
sure it would be a pretty high percentage.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

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

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top