Results 1 to 2 of 2

Thread: data difference

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    data difference

    I need to find the difference between a date entered in a form "txtDate" and the current date.

    If the person is less than 21 I need to pop up a message rejecting them and then redirecting them to a new page.

    Can anyone give me a bit of guidance on this. I am much more of a sever VBScript person.

    TIA

    Parksie

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    I can't say if this is the best way or not, but I've done it this was before:

    Code:
    <script langauge="JavaScript">
    function CalAge(bDay){
    now = new Date()
    born = new Date(bDay.value);
    years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
    
    return years;
    
    }
    
    function ReDir(iAge, sUrlUnderAge, sUrlOfAge){
    if(iAge < 21){
    	alert("You must be 21 to enter this page.  No redirecting you to: " + sUrlUnderAge);
    	location.href=sUrlUnderAge
    } else {
    	alert("Welcome, enjoy your stay!")
    	location.href=sUrlOfAge
    }
    }
    </script>
    
    
    <form>
    <input type="text" name="DofB" maxlength="10" size="12" onBlur="ReDir(CalAge(this), 'http://www.yahoo.com', 'http://www.realisticgraphics.com')">
    </form>
    Replace the URL parameters to the pages you want to redirect to. The first one is the site for under age users, the second is for of age users. This is by no means fool proof, obviously somebody could enter a fake date to get in, but it should answer your question though.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width