Solved

Over 18 disclaimer

Posted on 2006-11-17
6
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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