Non-functioning validation1
Hello one & all ,
The clientside validation i have implemented are not correctly working - a common problem is that form submission occurs irrespective of errors. This is a recurring problem across application and i am unable to solve the problem. Any help would be greatly appreciated. Below is an example of code.Thanks in advance,
larry101
LOGIN PAGE CODE
<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
Function checkInput)
If RadioGroupValid(login.usertype)= False Then
checkInput = False
MsgBox "You have forgotten to select a usertype",0,"ERROR"
Exit Function
End If
If TextBoxValid(login.username.value)= False Then
checkInput = False
MsgBox "The required number of characters for a username is 8",0,"ERROR"
Exit Function
End If
If TextBoxValid(login.password.value)= False Then
checkInput = False
MsgBox "The required number of characters for a password is 8",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> </TITLE>
</HEAD>
<BODY>
<CENTER><H2>LOGIN</H2></CENTER>
<FORM NAME="login" onSubmit="formValid()" 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>
Problem : when ok button on MsgBox ( which indicates the error ) is clicked , the form submits to the page in the ACTION attribute which redirects the user back to the login page. There are a couple of problems :
- when the user is returned to the login page , the previously entered information is automatically erased. Should the MsgBox when clicked not keep the user on the same page and leave any entered information intact ? This problem of a form submitting when incorrect/invalid input entered is occurring on several pages across the application I am working on. As can be seen , I am using VBScript for client-side validation and I want to keep this intact. Any suggestions what might be causing this problem ?
- is it possible to send a MsgBox back to the login page indicating that the users information cannot be located in the database in conjunction with a Response.Redirect to the login page ?
- when a Response.Redirect is used in a page to another page any information that had been entered by the user is erased. For example , user inputs data into a form which is submitted to a database , next page displayed indicates data submitted successfully. Upon clicking to return to the form , the user finds that all the fields are empty/default value. Again , any suggestions ?
|