Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Over 18 disclaimer

Posted on 2006-11-17
6
Medium Priority
?
336 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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