SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date manipulation & selection

    Hi there.

    I am writing a small script to allow users to add details of their forthcoming events.

    I want them to be able to select a date from a drop down menu.

    I want them to be able to select any date, from the current day onwards.

    This would involve 3 drop down boxes, a day, a month, and a year.

    How would I auto generate what was available to be selected based on the current day and month ?

    Cheers
    James

  2. #2
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, this here should work:
    PHP Code:

    <?PHP

    //Here I set the date of today
     
    $start=date("d.m.Y");
     
    $datarr explode(".",$start);
     
    $tagheute $datarr[0];
     
    $monheute $datarr[1];
     
    $jahrheute $datarr[2];

    echo 
    " <table width='250' border='0' cellspacing='0' cellpadding='0'>
         <tr>
          <td width='50'>
           <select name='starttag'>"
    ;
           for (
    $i=1$i<=31$i++)  { 
            echo 
    "
            <option "
    ;
             if (
    $i==$tagheute) echo " selected ";echo "value='$i'>$i."; }
           echo 
    "
           </select>&nbsp;
          </td>
          <td width='50'>
           <select name='startmonat'>"
    ;
           for (
    $i=1$i<=12$i++)  {
            echo 
    "
            <option "
    ;
             if (
    $i==$monheute) echo " selected ";echo "value='$i'>$i."; }
           echo 
    "
           </select>&nbsp;
          </td>
          <td width='150'>
           <select name='startjahr'>"
    ;
           for (
    $i=1$i<=2$i++)  {
            echo 
    "
            <option "
    ;
            
    $jahr $jahrheute-1+$i;
             if (
    $i==$jahrheute) echo " selected ";echo "value='$jahr'>$jahr"; }
           echo 
    "
           </select>
          </td>
         </tr>
        </table>"
    ;

    ?>

  3. #3
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, this section of code doesn't automatically select a year, "selected" never gets printed.

    Code:
    <select name='startjahr'>";
           for ($i=1; $i<=2; $i++)  {
            echo "
            <option ";
            $jahr = $jahrheute-1+$i;
             if ($i==$jahrheute) echo " selected ";echo "value='$jahr'>$jahr"; }
           echo "
    </select>

  4. #4
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, I just doublechecked it and couldn't find any problems. It's working fine. I get 3 drop down menues, day-month-year and all three with the date of today. Isn't that what you wanted?

  5. #5
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The drop downs are fine, it's the part of the code that's supposed to print 'selected' in the drop down for the year that doesn't work. Do a view source and look at the html produced and you'll see it's missing.

    i.e. today is july 1st 2001
    Code:
    <select name='starttag'>
            <option  selected value='1'>1
            <option value='2'>2
            etc.
    
    <select name='startmonat'>
            <option value='1'>1
            .
            .
            <option  selected value='7'>7
            etc.
    <select name='startjahr'>
            <option value='2001'>2001
            <option value='2002'>2002
           </select>

  6. #6
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh i see. That's just because the actuall year will always be on the first position, which is automatically selected. As you will never have the last year in the drop down menue, it's not a problem. But you will have to change the skript once a year.
    Sorry, I don't know any better way.


Bookmarks

Posting Permissions

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