Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Age Verification Javascript in Firefox will not work, IE works!
Old 02-18-2007, 03:45 PM Age Verification Javascript in Firefox will not work, IE works!
Junior Talker

Posts: 4
Trades: 0
Hey all, new here, first post, hopefully someone can lend a helpful hand to this problem.

In IE this script works fine, in Firefox (latest ver. 2.0.0.1) it doesn't.

What this script does...it asks the user in drop down boxes for their DOB as the content on the site this is for is a little over the top. If the user puts in something older than 18, it proceed to a page called ageok.html, otherwise it pops up with a message saying, "Sorry...You cannot enter". It stores if they can enter in a cookie and that way if the user returns, they do not have to enter their DOB again and it just proceeds to ageok.html. Of course, most of us erase our cookies regularly, but this is just for the company to protect themselves and keep little kids out.

Javascript from my index page:

Code:
<script language="javascript">
<!--

var pos = document.cookie.indexOf("UnderAge=");
if (pos == false)
{
  location = "ageok.html";
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }


function isDate(day,month,year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
    (month == test.getMonth()) &&
    (day == test.getDate()) )
    return true;
    else
    return false
}


function getMonthLength(month,year,julianFlag)
{
   var ml;
   if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10||month==12)
      {ml = 31;}
   else {
       if(month==2) {
          ml = 28;
          if(!(year%4) && (julianFlag==1 || year%100 || !(year%400)))
             ml++;
       }
       else
          {ml = 30;}
   }
   return ml;    
}


function CheckAge(form)
{
   var myLimit = 18;
   
    // Get Current Date
   Today=new Date();
   var yd = Today.getYear();
   var md = Today.getMonth();
   var dd = Today.getDate();
  
   // Get Date from the form
   var yb = form.yb.value;
   var mb = form.mb.options[form.mb.selectedIndex].value;
   var db = form.db.options[form.db.selectedIndex].value;
   
  
   
   MNames=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
      "Oct","Nov","Dec");
   
   
    if((db == 0) || 
       (mb == 0) || 
       (yb == 0))
   {
      alert("You must enter a valid date");
      return;
   }
   else
   {
        if (isDate(db,mb,yb)==false) 
            {
            alert("You must enter a valid date");
            return;
            }
   }
   
   
   
   // Month length 0->use calendar length
   var mLength = 0;
   // 0 if Gregorian, 1 is Julian
   var isJulian = 1;

   var ma=0;
   var ya=0;

   var da = dd-db;
   // This is the all-important day borrowing code.
   if(da<0)
   {
      md--;
      // Borrow months from the year if necesssary.
      if(md<1)
      {
     yd--;
     // Determine no. of months in year
     if(mLength)
        {md=md+parseInt(365/mLength);}
     else
        {md=md+12;}
      }
      if(mLength==0) // Use real month length if no fixed
      {              // length is indicated - note that we add a leap day if necessary.
         ml=getMonthLength(md,yd,isJulian);
     da=da+ml;
      } 
      // For this case, everything works like it did in elementary school.
      else
     {da+=mLength;} // Use fixed month length
   }

   ma = md - mb;
   // Month borrowing code - borrows months from years.
   if(ma<0)
   {
      yd--;
      if(mLength!=0)
     {ma=ma+parseInt(365/mLength);}
      else
     {ma=ma+12;}
   }

   ya = yd - yb;

    // Find if you are over AgeLimit.
    if(ya>=myLimit)
   {
      makeCookie("UnderAge",false);
      location = "ageok.html"; 
   }
   else
   {
      alert("Sorry, you are not allowed to view this site.");
   }

 }


//Cookie things

function makeCookie(cookieName,cookieData)
{
        var expiry = new Date();
        expiry.setTime(expiry.getTime() + 1 * (24 * 60 * 60 * 1000));
        setCookie(cookieName, cookieData, expiry);
}

function setCookie(cookieName, cookieData, expiry)
{
    document.cookie = cookieName + "=" + escape(cookieData) + "; expires=" + expiry.toGMTString();;
}


//-->
</SCRIPT>

</HEAD>

<body>       
  </span>
  <FORM METHOD="post" class="style2">
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TR><TH></TH><TH>Day</TH><TH>Month</TH><TH>Year
        

</TH></TR>
  <TR>
    <TD>Birthdate:&nbsp; </TD>
    <TD align=middle><SELECT style="LEFT: -1px; TOP: 0px" name=db> <OPTION 
        value=0 selected>[Day]<OPTION value=1>1<OPTION value=2>2<OPTION 
        value=3>3<OPTION value=4>4<OPTION value=5>5<OPTION value=6>6<OPTION 
        value=7>7<OPTION value=8>8<OPTION value=9>9<OPTION value=10>10<OPTION 
        value=11>11<OPTION value=12>12<OPTION value=13>13<OPTION 
        value=14>14<OPTION value=15>15<OPTION value=16>16<OPTION 
        value=17>17<OPTION value=18>18<OPTION value=19>19<OPTION 
        value=20>20<OPTION value=21>21<OPTION value=22>22<OPTION 
        value=23>23<OPTION value=24>24<OPTION value=25>25<OPTION 
        value=26>26<OPTION value=27>27<OPTION value=28>28<OPTION 
        value=29>29<OPTION value=30>30<OPTION value=31>31</OPTION></SELECT></TD>
    <TD><SELECT size=1 name=mb> <OPTION value=0 selected>[Month]<OPTION 
        value=1>January<OPTION value=2>February<OPTION value=3>March<OPTION 
        value=4>April<OPTION value=5>May<OPTION value=6>June<OPTION 
        value=7>July<OPTION value=8>August<OPTION value=9>September<OPTION 
        value=10>October<OPTION value=11>November<OPTION 
        value=12>December</OPTION></SELECT></TD>
    <TD align=middle><SELECT name=yb> <OPTION value=0 selected>[Year]<OPTION 
        value=1920>1920<OPTION value=1921>1921<OPTION value=1922>1922<OPTION 
        value=1923>1923<OPTION value=1924>1924<OPTION value=1925>1925<OPTION 
        value=1926>1926<OPTION value=1927>1927<OPTION value=1928>1928<OPTION 
        value=1929>1929<OPTION value=1930>1930<OPTION value=1931>1931<OPTION 
        value=1932>1932<OPTION value=1933>1933<OPTION value=1934>1934<OPTION 
        value=1935>1935<OPTION value=1936>1936<OPTION value=1937>1937<OPTION 
        value=1938>1938<OPTION value=1939>1939<OPTION value=1940>1940<OPTION 
        value=1941>1941<OPTION value=1942>1942<OPTION value=1943>1943<OPTION 
        value=1944>1944<OPTION value=1945>1945<OPTION value=1946>1946<OPTION 
        value=1947>1947<OPTION value=1948>1948<OPTION value=1949>1949<OPTION 
        value=1950>1950<OPTION value=1951>1951<OPTION value=1952>1952<OPTION 
        value=1953>1953<OPTION value=1954>1954<OPTION value=1955>1955<OPTION 
        value=1956>1956<OPTION value=1957>1957<OPTION value=1958>1958<OPTION 
        value=1959>1959<OPTION value=1960>1960<OPTION value=1961>1961<OPTION 
        value=1962>1962<OPTION value=1963>1963<OPTION value=1964>1964<OPTION 
        value=1965>1965<OPTION value=1966>1966<OPTION value=1967>1967<OPTION 
        value=1968>1968<OPTION value=1969>1969<OPTION value=1970>1970<OPTION 
        value=1971>1971<OPTION value=1972>1972<OPTION value=1973>1973<OPTION 
        value=1974>1974<OPTION value=1975>1975<OPTION value=1976>1976<OPTION 
        value=1977>1977<OPTION value=1978>1978<OPTION value=1979>1979<OPTION 
        value=1980>1980<OPTION value=1981>1981<OPTION value=1982>1982<OPTION 
        value=1983>1983<OPTION value=1984>1984<OPTION value=1985>1985<OPTION 
        value=1986>1986<OPTION value=1987>1987<OPTION value=1988>1988<OPTION 
        value=1989>1989<OPTION value=1990>1990<OPTION value=1991>1991<OPTION 
        value=1992>1992<OPTION value=1993>1993<OPTION value=1994>1994<OPTION 
        value=1995>1995<OPTION value=1996>1996<OPTION value=1997>1997<OPTION 
        value=1998>1998<OPTION value=1999>1999</OPTION></SELECT></TD></TR>
<TR>
<TD align=middle colSpan=4>
      <P align="center"><BR><INPUT id=Enter onclick=CheckAge(this.form) type=button value="Enter Site" name=Enter></P></TD>
</TR>
</TABLE>
</FORM>
Javascript from my ageok.html page:

Code:
  <SCRIPT LANGUAGE=javascript>
<!--
var pos = document.cookie.indexOf("UnderAge=");

if (pos != false)
{
  location = "index.html";
}
//-->
</SCRIPT>
I really don't know javascript all that well and I can't find anything that seems incorrect. Any help or ideas to make this more compatible?

THANK YOU! Seriously. Any help will be GREATLY appreciated.
cg333 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-19-2007, 06:26 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by cg333 View Post
What this script does...it asks the user in drop down boxes for their DOB as the content on the site this is for is a little over the top. If the user puts in something older than 18, it proceed to a page called ageok.html, otherwise it pops up with a message saying, "Sorry...You cannot enter". It stores if they can enter in a cookie and that way if the user returns, they do not have to enter their DOB again and it just proceeds to ageok.html. Of course, most of us erase our cookies regularly, but this is just for the company to protect themselves and keep little kids out.
You said you'd like useful help with this problem and that you'll appreciate any help you get. So I'm going to tell you what you don't want to hear.

Your script is very broken. It doesn't verify someone's age, it verifies that they can do basic math. If you're trying to protect yourself against legal things like lawsuits, well, the law says you have to verify that a person is actually 18, not that they say they are. Also, if someone is honest, then gets denied, they can just clear the cookie and try again.

Trying to fix cross-browser issues with this particular script would be a waste of your time.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-19-2007, 06:39 PM Re: Age Verification Javascript in Firefox will not work, IE works!
memberpro's Avatar
Super Talker

Posts: 143
Trades: 0
Quote:
Originally Posted by Learning Newbie View Post
If you're trying to protect yourself against legal things like lawsuits, well, the law says you have to verify that a person is actually 18, not that they say they are. Also, if someone is honest, then gets denied, they can just clear the cookie and try again.
I am curious... given our current level of internet technology.... how could you verify that someone is over the age of 18? The only way that I can think of is by credit card and if anyone has been a victim of identiy fraud (like me) then that is not something they will freely give out.

So what is the solution.....? Hmmmmm...
__________________

Please login or register to view this content. Registration is FREE
- step-by-step learn how to design, create and install your own website in hours...not days.
Please login or register to view this content. Registration is FREE
was never so easy.
memberpro is offline
Reply With Quote
View Public Profile
 
Old 02-19-2007, 06:40 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Novice Talker

Posts: 11
Name: Matthew Bagley
Trades: 0
Well the code works in my FireFox version 2, if you go to the error console what is the error?

Also as Learning Newbie stated this wont proove the person is over 18, used inconjunction with a disclaimer where they have to sign a name then it would act as a record but this will not protect people under 18 from visiting the site.
__________________
Matthew Bagley
Paramiliar Design Studios

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
neomaximus2h is offline
Reply With Quote
View Public Profile Visit neomaximus2h's homepage!
 
Old 02-20-2007, 05:22 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Junior Talker

Posts: 4
Trades: 0
Thank you all for your replies. I am actually not worried with it from a completely legal point of view. There are no drugs, alc, pron or anything of the sort. I don't need it to verify credit cards or anything. I just want to know that for that person to enter the site, they had to say they were over 18. It isn't my deal, in this case, if they say they are over when they are not. Lots of alcoh. sites do this similar sorta thing. Know what I mean?

As far as the errors, not really sure what to provide you? It basically just says sorry, you cannot enter as if it isn't storing or reading the cookie or maybe there is a problem in the script. I have tried it on other firefox versions and it works fine. Maybe just interference with one of my plugins?

Thank you,
-d
cg333 is offline
Reply With Quote
View Public Profile
 
Old 02-20-2007, 06:16 PM Re: Age Verification Javascript in Firefox will not work, IE works!
memberpro's Avatar
Super Talker

Posts: 143
Trades: 0
How about putting two graphics with hyperlinks attached - one says "Yes I am over 18 years old" the other says "I am under 18 please don't show me any naked girls"

I think this would be cross-browser compliant... not sure though.
__________________

Please login or register to view this content. Registration is FREE
- step-by-step learn how to design, create and install your own website in hours...not days.
Please login or register to view this content. Registration is FREE
was never so easy.
memberpro is offline
Reply With Quote
View Public Profile
 
Old 02-20-2007, 06:34 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by memberpro View Post
I am curious... given our current level of internet technology.... how could you verify that someone is over the age of 18? The only way that I can think of is by credit card and if anyone has been a victim of identiy fraud (like me) then that is not something they will freely give out.
Credit card, pure and simple. People use these online for any number of reasons, age verification being one of them. While there's a lot of worry about ID fraud, there is also a lot of prevention in place because of that hype. If someone charges a HDTV to your credit card, you just tell them it wasn't you, and magically your account refills itself. Maybe there's another way, if they gave you your social security number you might be able to look things up, but that would be far more dangerous than using a credit card for this.

And in the end the question boils down to: do you want to verify that your users are at least 18, or not?
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-20-2007, 07:26 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Junior Talker

Posts: 4
Trades: 0
This post is growing, this board is awesome. New bookmark just added.

memberpro-As far as the graphic idea, that isn't very formal or official. Although - entertaining.

I wanted something in between the graphic idea and credit card verifying and this is as close to that as I can come.

Even verifying a credit card these days is touchy, many users wouldn't enter that in to view a site they aren't absolutely in need of viewing. Especially with the masking of domain names, fraudulent verification logos and such...

Again, this site doesn't contain anything that technically should even be blocked for the under 18, but some of the pictures are sexually suggestive and the wording in certain parts isn't something mommy would like in some households. Hence my reasoning.

THE ACTUAL JAVASCRIPT PROBLEM! haha. So I opened my error console and when I click enter site, nothing outputs. I simply get the message, Sorry, you cannot enter site. No clue why this is happening. Any other tests or ideas? I really only think its FF 2.0.0.1 cause all my other browsers are happy as clams.

Take care, c
cg333 is offline
Reply With Quote
View Public Profile
 
Old 02-20-2007, 08:05 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Download FireBug and use their javascript debugger.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-20-2007, 08:57 PM Re: Age Verification Javascript in Firefox will not work, IE works!
Junior Talker

Posts: 4
Trades: 0
So I tried it on another machine with FF 2.0.0.1 and it errors also, not letting me past the first page. With firebug, Im not 100% sure what I am looking for...I click the script tab, set to break on all errors, say inspect and it puts me back to the html tab where some stuff is red (mainly style stuff I haven't put into the css sheet yet) when I go back to the script tab its just all black. Any help here?

Thank you.
cg333 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Age Verification Javascript in Firefox will not work, IE works!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40961 seconds with 12 queries