Non-functioning validation2
Hi all - again. Validation is my nemises!!
The problem with this code is that error messages are showing but form is submitted anyway. Also if NewPassword is different from ConfirmNewPassword , the string/value of NewPassword is submitted
and entered into the database irrespective of error. Once again , thankyou for taking time to read this and offer any solutions,
cheers,
larry101
CHANGE PASSWORD PAGE CODE
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
Function TextBoxValid(textbox)
Dim textlen
TextBoxValid = True
textlen = Len(textbox)
If textlen <> 8 Then
TextBoxValid = False
End If
End Function
Function checkInput
If TextBoxValid(ChangePass.NewPassword.value)= False Then
checkInput = False
MsgBox "The required number of characters for a password is 8",0,"ERROR"
Exit Function
End If
If TextBoxValid(ChangePass.ConfirmNewPassword.value)= False Then
checkInput = False
MsgBox "The required number of characters for password confirmation is 8",0,"ERROR"
Exit Function
End If
If ((ChangePass.NewPassword.value) <> (ChangePass.ConfirmNewPassword.value)) Then
checkInput = False
MsgBox "The new password you entered does not match the confirm password.
Please re-enter",0,"ERROR"
Exit Function
End If
End Function
Function formValid()
If checkInput = True Then
formValid = True
Else
formValid = False
End If
End Function
</SCRIPT>
<TITLE>Update User Password</TITLE>
</HEAD>
<BODY>
<FORM NAME="ChangePass" ACTION="UpdatePassTable.asp" METHOD="POST" onSubmit="formValid()">
Old Password :         &nbs p     
<INPUT TYPE="Password" NAME="OldPassword" SIZE="8" MAXLENGTH="8">
<BR>
<BR>
New Password :         &nbs p   
<INPUT TYPE="Password" NAME="NewPassword" SIZE="8" MAXLENGTH="8">
<BR>
Confirm New Password :
<INPUT TYPE="Password" NAME="ConfirmNewPassword" SIZE="8" MAXLENGTH="8">
<BR>
<BR>
<INPUT TYPE="Submit" VALUE="Submit">
 
 
<INPUT TYPE="Reset" VALUE="Reset">
<BR>
</TABLE>
</FORM>
</BODY>
</HTML>
UpdatePassTable.asp CODE â checks usertype and updates the associated table
<% @LANGUAGE=VBScript %>
<%
Dim objConn, query, objRS
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=Profiles&Placements"
If (Session("usertype") =0) Then
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "TPCLogin", objConn, adOpenDynamic, adLockOptimistic
While Not objRS.EOF
If (objRS("username") = Session("username")) Then
objRS.Delete
End If
objRS.MoveNext
Wend
objRS.Close
query = "SELECT * FROM [TPCLogin]"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open query, objConn, adOpenDynamic, adLockOptimistic
objRS.AddNew
objRS("username")= Session("username")
objRS("password")= Request.Form("NewPassword")
objRS.Update
Else
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "StudLogin", objConn, adOpenDynamic, adLockOptimistic
While Not objRS.EOF
If (objRS("username") = Session("username")) Then
objRS.Delete
End If
objRS.MoveNext
Wend
objRS.Close
query = "SELECT * FROM [StudLogin]"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open query, objConn, adOpenDynamic, adLockOptimistic
objRS.AddNew
objRS("username")= Session("username")
objRS("password")= Request.Form("NewPassword")
objRS.Update
End If
objRS.Close
Set objRs = Nothing
objConn.Close
Set objConn = Nothing
Response.Redirect "UserTypeCheck.asp"
%>
|