Solved

Over 18 disclaimer

Posted on 2006-11-17
6
328 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now