SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I make my drop down date be set to today by default??

    Hello all!!

    I've been researching on how to do this without much success.

    Can you helpme with two things:

    1. I am trying to figure out a way that when the user uses the back button the selected date he had chosen stays selected.

    2. Also, is there away for the default date to be set to the current days date?

    PHP Code:
    <select name="entregaano" class="form">
                              <
    option  value=2006 selected>2006</option>
                            </
    select>
                            - 
                            <
    select name="entregames" class="form">
                              <
    option value="" selected>mÍs</option>
                              <
    option  value=1>1</option>
                              <
    option  value=2>2</option>
                              <
    option  value=3>3</option>
                              <
    option  value=4>4</option>
                              <
    option  value=5>5</option>
                              <
    option  value=6>6</option>
                              <
    option  value=7>7</option>
                              <
    option  value=8>8</option>
                              <
    option  value=9>9</option>
                              <
    option  value=10>10</option>
                              <
    option  value=11>11</option>
                              <
    option  value=12>12</option>
                            </
    select>
                            - 
                            <
    select name="entregadia" class="form">
                              <
    option value="" selected>dia</option>
                              <
    option  value="1">1</option>
                              <
    option  value="2">2</option>
                              <
    option  value="3">3</option>
                              <
    option  value=4>4</option>
                              <
    option  value=5>5</option>
                              <
    option  value=6>6</option>
                              <
    option  value=7>7</option>
                              <
    option  value=8>8</option>
                              <
    option  value=9>9</option>
                              <
    option  value=10>10</option>
                              <
    option  value=11>11</option>
                              <
    option  value=12>12</option>
                              <
    option  value=13>13</option>
                              <
    option  value=14>14</option>
                              <
    option  value=15>15</option>
                              <
    option  value=16>16</option>
                              <
    option  value=17>17</option>
                              <
    option  value=18>18</option>
                              <
    option  value=19>19</option>
                              <
    option  value=20>20</option>
                              <
    option  value=21>21</option>
                              <
    option  value=22>22</option>
                              <
    option  value=23>23</option>
                              <
    option  value=24>24</option>
                              <
    option  value=25>25</option>
                              <
    option  value=26>26</option>
                              <
    option  value=27>27</option>
                              <
    option  value=28>28</option>
                              <
    option  value=29>29</option>
                              <
    option  value=30>30</option>
                              <
    option  value=31>31</option>
                            </
    select
    Thank you all my lovely friends!

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following code for the default selection of dates...

    Code:
    <form name="frm" method="post">
        DAY::::
      <select name="selDay">
        <?
    	  for($i=1;$i<=31;$i++)
    	    {
    	?>
    	  <option value="<? echo $i;?>"<? if (date("d")==$i){ ?> selected <? } ?>><? echo $i;?></option>
    	<?	
    		}
    	?>
      </select>
      MONTH::::
        <select name="selMonth">
        <?
    	  for($j=1;$j<=12;$j++)
    	    {
    	?>
    	      <option value="<? echo $j;?>"<? if (date("m")==$j){ ?> selected <? } ?>><? echo $j;?></option>
    	<?	
    		}
    	?>
      </select>
       YEAR:::::
      <select name="selYear">
        <?
    	  for($k=2005;$k<=2010;$k++)
    	    {
    	?>
    	    <option value="<? echo $k;?>"<? if (date("Y")==$k){ ?> selected <? } ?>><? echo $k;?></option>
    	<?	
    		}
    	?>
      </select>
    </form>

  3. #3
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gracias PragyaRatna !!

    One final question, is it possible to use that code you provided and make it so so that when the user goes back the date he selected stays selected?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    UK
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, search for sticky forms.

  5. #5
    SitePoint Evangelist DMacedo's Avatar
    Join Date
    May 2004
    Location
    Braga, Portugal
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a small optimization, do not use a dynamic function call inside a loop when you can place it outside. The date() function calls can be replaced with variables:

    PHP Code:
    $today_day date('d');
    $today_month date('m');
    $today_yeat date('Y'); 
    ~ Daniel Macedo


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
  •