Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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
  #1 (permalink)  
Old April 24th, 2004, 09:35 AM
Authorized User
Join Date: Mar 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validating a form field against a database

I retrieve a password from my database and set Session("Password").

Later, in my OnClick event, I try to compare the password that the user enetered on the form to Session("Password"). I get "Error on Page". I know Session("Password") contains the correct value because I display it BEFORE the onlick event is called. But it is not accessible from within the OnClick event. Is my timing off? How do I do this???

Thanks in advance!

Sub btnSubmit_OnClick()
  ' Check for password change
  If Len(frmAdd.Password.value) > 0 then
    If (frmAdd.Password.value <> Session("Password")) then
      Alert("The password that you entered does not match our files. Please correct.")
      Exit Sub
    End if
End Sub

  #2 (permalink)  
Old April 24th, 2004, 10:20 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

You're mixing client side and server side code. Sessions live on the server, while the OnClick will fire in the browser. To do what you want to do, either submit the page to the server and compare there, or send the value of the Session variable to the client, like this:

If (frmAdd.Password.value <> '<%=Session("Password")%>') then

IMO, storing passwords in client side code is not really a good and secure idea, so maybe you're better off posting to the server.....


Imar Spaanjaars
Everyone is unique, except for me.

  #3 (permalink)  
Old April 24th, 2004, 04:07 PM
Authorized User
Join Date: Mar 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Thank you so much for your help. It straightend my thinking out. You will never know how much I appreciate this kind of assistance from you and people like yourself!

Similar Threads
Thread Thread Starter Forum Replies Last Post
compare form field to database before submit chelle60 Javascript How-To 3 January 2nd, 2007 05:42 AM
Validating textbox in field level Paula222 Access VBA 5 February 15th, 2006 11:57 AM
Adding multiple form field values to database cdenequolo Classic ASP Basics 1 August 17th, 2004 05:38 PM
Validating a hidden field mkerchenski ASP.NET 1.0 and 1.1 Basics 1 June 3rd, 2004 11:20 AM
validating rich text field for attachment Mimi Javascript How-To 4 August 25th, 2003 03:12 AM

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