Solved

Over 18 disclaimer

Posted on 2006-11-17
6
331 Views
Last Modified: 2010-08-05
Hi there,
I have page that takes information form the user but i need to trigger a flag or better yet to redirect she/he to a pdf depending on his/her age. Is there a way to do this an ASP?
if the filed Date of Birth is filed with a date that is not over 18 then take it to the PDF, I'm not so sure if the need of AJAX is need it here, but i'm new to ASP and not to mention AJAX (LOL) so any suggestion will be apreciate it
Thanks
JSCTECHY
0
Comment
Question by:jsctechy
  • 4
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
deathtospam earned 500 total points
ID: 17966183
jsctechy --

This script should help demonstrate how to get the job done.

================================================
<%
      Option Explicit

      Dim bIsPostback, sMonth, sDay, sYear, iMonth, iDay, iYear
      Dim dtUserDateOfBirth, iUserAge, sDisplayMessageHTML

      '// Use this constant to control the minimum age requirement.
      Const MINIMUM_AGE_IN_YEARS = 18

      bIsPostback = (Trim(Request("IsPostback")) <> "")

      If NOT bIsPostback Then
            '// First visit to the page -- set all field values to be empty.
            sMonth = "":  sDay = "":  sYear = ""
      Else
            '// User has already submitted the form at least once -- retrieve the form values.
            sMonth = Trim(Request("DOBMonth"))
            sDay = Trim(Request("DOBDay"))
            sYear = Trim(Request("DOBYear"))

            If IsNumeric(sMonth) AND IsNumeric(sDay) AND IsNumeric(sYear) Then
                  '// The form values are all valid numbers.
                  iMonth = CLng(Request("DOBMonth"))
                  iDay = CLng(Request("DOBDay"))
                  iYear = CLng(Request("DOBYear"))

                  '// Use the form values to build the user's birth date.
                  dtUserDateOfBirth = DateSerial(iYear, iMonth, iDay)

                  '// Find out how many years old the user is.
                  iUserAge = DateDiff("yyyy", dtUserDateOfBirth, Now())
                  Call Response.Write("User is " & iUserAge & " years old [born on <u>" & DateValue(dtUserDateOfBirth) & "</u>]<br>" & vbNewLine)

                  '// Perform the age validation.
                  If (iUserAge >= MINIMUM_AGE_IN_YEARS) Then
                        Call Response.Write("User is at least " & MINIMUM_AGE_IN_YEARS & " years of age.<br>" & vbNewLine)
                  Else
                        Call Response.Write("User is not " & MINIMUM_AGE_IN_YEARS & " years old -- access denied.<br>" & vbNewLine)
                  End If
                  
                  '// Stop processing the page.
                  Call Response.End()
            End If
      End If
%>
<html>
      <head><title>How To Validate Age Using Classic ASP</title></head>
      <body>
            <form action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="post">
            <input type="hidden" name="IsPostback" value="True">

            <table>
                  <tr>
                        <td>Month</td>
                        <td><input type="text" name="DOBMonth" size="10" value="<%=Server.HTMLEncode(sMonth)%>"></td>
                  </tr>
                  <tr>
                        <td>Day</td>
                        <td><input type="text" name="DOBDay" size="10" value="<%=Server.HTMLEncode(sDay)%>"></td>
                  </tr>
                  <tr>
                        <td>Year</td>
                        <td><input type="text" name="DOBYear" size="10" value="<%=Server.HTMLEncode(sYear)%>"></td>
                  </tr>
                  <tr><td colspan="2">&nbsp;</td></tr>
                  <tr>
                        <td colspan="2"><input type="submit" value="Submit"></td>
                  </tr>
            </table>
      </body>
</html>
================================================

-= DeathToSpam =-
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17966301
that seems to work properly, but if i want to direct the user if is < 18 years old to a pdf called Apply.pdf and if it is over continue to another page called Application.asp how would i add those to thing on this code?
Thanks
0
 
LVL 9

Expert Comment

by:deathtospam
ID: 17966455
Then modify the part of my code that does the age validation:

<%
              '// Perform the age validation.
               If (iUserAge >= MINIMUM_AGE_IN_YEARS) Then
                    'Call Response.Write("User is at least " & MINIMUM_AGE_IN_YEARS & " years of age.<br>" & vbNewLine)
                    Call Response.Redirect("http://www.somewhere.com/Application.asp")
               Else
                    'Call Response.Write("User is not " & MINIMUM_AGE_IN_YEARS & " years old -- access denied.<br>" & vbNewLine)
                    Call Response.Redirect("http://www.somewhere.com/Apply.pdf")
               End If
%>


-= DeathToSpam =-
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:jsctechy
ID: 17967843
do they have to be links like that?
or can i just have this?
>> Call Response.Redirect("application.asp")
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17967899
Also when i add all this code to my page i got an error saying
Microsoft VBScript compilation error '800a0400'

Expected statement

/sp/volunteer/index.asp, line 185

Option Explicit
^
0
 
LVL 1

Author Comment

by:jsctechy
ID: 17967912
disregard that error i have put it after the html tags and thats the reaon why i was getting it ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Attaching a file to SMTP in Classic ASP 1 43
JSON error 4 71
Summernote and form validation 10 192
XML and version of MS XML Dom Document versions 5 13
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question