client-side validation using VBScript
Hi all ,
am new to ASP, have bought thw book "Beginning Active Server pages3.0". I am trying to develop an application that involves :
VBScript
ASP
MS Access.
have encountered a problem with client-side validation - the fields are checked ok but on clicking the "ok" button in the msgbox the form is submitted. Even if the fields are empty the form is still submitted. Upon submission,an error page is displayed. Any help or advice would be greatly appreciated.
Coding follows :
Login Page Coding
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
Function RadioGroupValid(radGroup)
Dim radNo
RadioGroupValid = False
For radNo=0 to radGroup.Length-1
If radGroup(radNo).Checked = True Then
RadioGroupValid = True
End If
Next
End Function
Function TextBoxValid(textbox)
Dim textlen
TextBoxValid = True
textlen = Len(textbox)
If textlen <> 8 Then
TextBoxValid = False
End If
End Function
Sub checkInput
validity = True
If Not RadioGroupValid(login2.usertype) Then
MsgBox "You have forgotten to select a usertype"
validity = False
End If
If Not TextBoxValid(login2.username.value) Then
MsgBox "The required number of characters for a username is 8"
validity = False
End If
If Not TextBoxValid(login2.password.value) Then
MsgBox "The required number of characters for a password is 8"
validity = False
End If
End Sub
</SCRIPT>
<TITLE>Placement_&_Profile_Application_Login</TITLE>
</HEAD>
<BODY>
<CENTER><H2>LOGIN</H2></CENTER>
<FORM NAME="login2" onSubmit="checkInput" ACTION="CheckLogin.asp" METHOD="POST">
Please indicate the type of user you are by selecting from either
<BR>
<input type="radio" name="usertype" value="0">Placement Co-ordinator
<BR>
<input type="radio" name="usertype" value="1">Student
<BR>
<BR>
Please enter both your Username and password.
<BR>
<BR>
Username : <input type="text" name="username" value="" size="8" maxlength="8">
<BR>
Password : <input type="password" name="password" value="" size="8" maxlength="8">
<BR>
<BR>
<input type="Submit" name="Submit" value="Login">
<input type="Reset" name="Reset" value="Clear">
<BR>
<BR>
</FORM>
</BODY>
</HTML>
Login details checked against database
should be no interface
<%
Dim Utype, Uname, Pword
Utype = Request.Form("usertype")
Uname = Request.Form("username")
Pword = Request.Form("password")
If Utype = "0" Then
Dim rsUser,Query1
set rsUser = Server.CreateObject("ADODB.Recordset")
Query1 = "SELECT * FROM TPCLogin WHERE username = '" & Uname & "';"
rsUser.Open Query1, objConn
If rsUser.EOF Then
Response.Write "The Username you have entered cannot be found,please check your input."
Response.Write "If entered correctly,please consult the Teaching & Practice Co-ordinator"
ElseIf
While Not rsUser.EOF
If UCase(rsUser("password")) != UCase(strPassword) Then
Response.Write "The password you have entered is incorrect,please check and re-enter."
End If
Else
Response.Redirect ChangePass.asp
End If
rsUser.Close
Set rsUser = Nothing
%>
Database connection Coding
<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Profiles&Placements"
Dim strUsername
strUsername = Request.Form("username")
%>
|