Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2004, 09:31 AM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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")

%>





 
Old September 1st, 2004, 11:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

I believe you have to return a false value for the submit to be stopped, so add return false somewhere (and make it a function).

Brian
 
Old September 1st, 2004, 10:27 PM
Authorized User
 
Join Date: Aug 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is it a "onSubmit" thing for vbscript using like <form onSubmit>?
so far, for javascript it works but not vbscript!
try this:

<script language=vbscript>
function formName_onSubmit()
        checkInput
......
        if invalid then
           formName_onSubmit=false
        else
           formName_onSubmit=true
        end if
end function
</script>


or function submitbuttonName_onClick()
            submitButtonName_onClick=true/false
   end function
that works for me



 
Old September 2nd, 2004, 02:19 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default


  Its

  function formname_onsubmit()
    formname_onsubmit=false
  end function






Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript for Client-side controls in ASP.net cJeffreywang ASP.NET 1.0 and 1.1 Professional 1 March 22nd, 2007 08:02 PM
Client Side Validation anujrathi ASP.NET 1.0 and 1.1 Professional 1 June 17th, 2006 10:23 PM
checkbox validation on client side using Javascrip sansircar ASP.NET 1.0 and 1.1 Professional 0 October 17th, 2005 07:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.