Click to See Complete Forum and Search --> : VBScript validation problems


larry101
September 14th, 2004, 11:12 AM
Hello one & all ,
I am relatively new to scripting. I am working on an application which involves asp and ms access2000. It writes to and reads from the database. The clientside validation i have implemented are not correctly working - a common problem is that form submission occurs irrespective of errors. 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 ?

Vanny
September 20th, 2004, 03:37 AM
I think you need to look up session variables and how the work this will solve your problems on displaying messages once the page has been submitted and redirected, and storing/passing information between one page and another.

Simple put a session variable is a variable that can store information between pages and for long periods of time. Default timeout is 20 minutes i think.

its use is soemthing along the lines of

session("test") = "anything you want"

This information can be used on an pages within the working ASP area. Eg the current website, its not transferrable between one domain to another.

a couple of donts though.
Dont create a database object in a session variable.