Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2004
    Thanked 0 Times in 0 Posts

    Question 2 questions involving dates in a form

    I have a reservation form that I am developing for a club...
    how do I a) set the reservation field so that the input type and drop down menus are set for today's date(like on orbits.com)

    and b)how do I set up the date of birth field so that it can validate that the client is at least 21 years of age?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Thanked 0 Times in 0 Posts
    Well it looks like orbitz.com is using a server-side language (like PHP or ASP) to generate their pages.

    So what you might have is the following:
    PHP Code:
     $months = array();
    $months[0] = 'Jan';
    $months[1] = 'Feb';
      * if month=Jan, output <option value="0" selected>Jan</option>
      * else, <option value="0">Jan</option>
    echo '<select name="month">';
    $months as $i=>$month) { 
    '<option value="'.$month.'"';
    date('M') == $month//select today's month
    echo ' selected';

    echo '<select name="day">';
    $i 1$i <= 31$i++) { 
    '<option value="'.$i.'"';
    date('j')*== $i//select today's day
    echo ' selected';
    As far as validating their age, it depends if you want the age validated before submit or after submit. If before, you'd use Javascript; if after, you'd use a server-side language like PHP or ASP.

    Basically you have to put the month, day, and year together and create a date.

    PHP Code:
    function myAge($m$d$y) {
    $dob_m $m;
    $dob_d $d;
    $dob_y $y;
    $tdy_m date('n');
    $tdy_d date('j');
    $tdy_y date('Y');
    $diff_y $tdy_y $dob_y;
    $diff_m $tdy_m $dob_m;
    $diff_d $tdy_d $dob_d;
    $diff_m 0) || ($diff_m == && $diff_d 0)) {
    $diff_y -= 1;

    function myAge(m, d, y) {
     var dob_m = m;
     var dob_d = d;
     var dob_y = y;
     var tdy = new Date();
     var tdy_m = tdy.getMonth();
     var tdy_d = tdy.getDate();
     var tdy_y = tdy.getFullYear();
     var diff_y = tdy_y - dob_y;
     var diff_m = tdy_m - dob_m;
     var diff_d = tdy_d - dob_d;
     if((diff_m < 0) || (diff_m == 0 && diff_d < 0)) {
      diff_y -= 1;
     return diff_y;
    You may want to read up a bit more on onsubmit and form validation if you choose the Javascript method.

    Hope that helps,


    Posting Permissions

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