Page 1 of 1

date selection boxes

Posted: Mon Feb 05, 2007 9:53 am
by hame22
Hi I have 3 list menus where a user can select the day month and year.

What I want to be able to do is make the list menus default to todays date automatically.

Is there a script out there that can allow this?

Thanks in advance

Posted: Mon Feb 05, 2007 9:55 am
by feyd
When writing out the options, compare the value to today's values.

:idea:

Posted: Mon Feb 05, 2007 10:26 am
by visitor-Q
something like this:

Code: Select all

$today = date("m"."d"."y");
        $today = explode($today);

        (($today[0] >= 1 && $today[0] <= 9) ? ($today[0] = "0". $today[0]) : (""));
        (($today[1] >= 1 && $today[1] <= 9) ? ($today[1] = "0". $today[1]) : (""));
        (($today[2] >= 1 && $today[2] <= 9) ? ($today[2] = "0". $today[2]) : (""));
        $thisMonth = $today[0];
        $thisDay = $today[1];
        $thisyear = $today[2];

        $month_array = array("01" => "January", "02" => "February", "03" => "March",
                             "04" => "April", "05" => "May", "06" => "June",
                             "07" => "July", "08" => "August", "09" => "September",
                             "10" => "October", "11" => "November", "12" => "December");

        echo "<SELECT NAME=\"event_month\">\n".
             "<OPTION VALUE=\"\">select a month\n";

        foreach($month_array as $key => $val){
                echo "<OPTION VALUE=\"". $key . (($key == $thisMonth) ? (" SELECTED") : ("")) ."\">". $val ."\n";
        }
        echo "</SELECT><br />\n";


        $days = range(1, 31);
        echo "<SELECT NAME=\"event_day\">\n".
             "<OPTION VALUE=\"\">select a day\n";

        foreach($days as $day){
                if($day >= 1 && $day <= 9){
                        $day = "0". $day;
                }
                echo "<OPTION VALUE=\"". $day . (($day == $thisDay) ? (" SELECTED") : ("")) ."\">". $day ."\n";
        }
        echo "</SELECT><br />\n";


        $years = range(2005, 2010);
        echo "<SELECT NAME=\"event_year\">\n".
             "<OPTION VALUE=\"\">select a year\n";

        foreach($years as $year){
                echo "<OPTION VALUE=\"". $year . (($year == $thisYear) ? (" SELECTED") : ("")) ."\">". $year ."\n";
        }
        echo "</SELECT>";
untested.