SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    default to todays date in select box

    Hi,

    I have a 3 dropdown lists beside each other to select a date:
    PHP Code:
    <select name="day">
                <
    option selected>day</option>
                <
    option value="01">01</option>
                <
    option value="02">02</option>
                <
    option value="03">03</option>
                <
    option value="04">04</option>
                <
    option value="05">05</option>
                <
    option value="06">06</option>
                <
    option value="07">07</option>
                <
    option value="08">08</option>
                <
    option value="09">09</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>
              <
    select name="month">
                <
    option selected>month</option>
                <
    option value="01">January</option>
                <
    option value="02">February</option>
                <
    option value="03">March</option>
                <
    option value="04">April</option>
                <
    option value="05">May</option>
                <
    option value="06">June</option>
                <
    option value="07">July</option>
                <
    option value="08">August</option>
                <
    option value="09">September</option>
                <
    option value="10">October</option>
                <
    option value="11">November</option>
                <
    option value="12">December</option>
              </
    select>
              <
    select name="year">
                <
    option selected>year</option>
            <
    option value="2003">2003</option>
            <
    option value="2002">2002</option>
                <
    option value="2001">2001</option>
              </
    select
    How cna I make it so that todays date is automatically selected?

    Thanks,
    Martin

  2. #2
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depends if you want to do it server side or client side.

    If server side (ASP/PHP) then put the selected in todays date.

    I suspect however you mean client side, in which case write yourself a little JavaScript programme that runs once the page has loaded and sets the current date to selected.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  3. #3
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    sorry - should have given more detail - I am looking for a clientside javascript to do this. I dont know javascript very well so could you point me to a script that does this or a tutorial or something?

    Thanks.

  4. #4
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Heres a related question....
    I have this little script to get todays date:

    PHP Code:
    <script type="text/javascript">
    var 
    = new Date()
    document.write(d.getDate())
    document.write(d.getMonth() + 1)
    document.write(d.getFullYear())
    </script> 
    This outputs the date as 1122003 for 11 Feb, 2003. How can I make this 11022003 (as I am passing this value to a DB with a date value)

    Thanks,
    Martin

  5. #5
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    var d = new Date();
    document.write(d.getDate());
    if(d.getMonth() < 9)
    {
      document.write("0");
    }
    document.write(d.getMonth() + 1);
    document.write(d.getFullYear());
    </script>
    - sorry no time now to spend on previous question.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  6. #6
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dale....

    now, what i need to do is have the date in the URL like this:

    <a href="track11022003.html">Todays results</a>

    Do you know how to do that? I can do it in PHP but the server this is goin on wont have PHP installed so it has to be javascript

  7. #7
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>New Document</title>
    <script type="text/javascript">
    
    function DoLoadThings()
    {
        SetLink();
        SetDropDown(); // In answer to question one - to be filled in later
    }
    
    function SetLink()
    {
        var LinkObj = document.getElementById("Link");
        var NewLink = "track";
    
        var d = new Date();
        NewLink += d.getDate();
        if(d.getMonth() < 9)
        {
          NewLink += "0";
        }
        NewLink += (d.getMonth()+1);
        NewLink += d.getFullYear();
        NewLink += ".html";
    
        LinkObj.href = LinkObj;
    }
    
    function SetDropDown()
    {
    }
    </script>
    </head>
    <body onLoad="DoLoadThings();">
    
    <a id="Link" href="">Todays Results</a>
    
    </body>
    </html>
    hth
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  8. #8
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    thanks for the code but I am afraid it isnt working.

    I added the script exactly as it is below but nothing is appearing in the href for the link.

    Any ideas what the problem is?

    Thanks,
    Martin

  9. #9
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't say I tested it try
    Code:
    LinkObj.href = NewLink;
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  10. #10
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added that line after this code:

    PHP Code:
     var LinkObj document.getElementById("Link");
        var 
    NewLink "track"
    It is now adding the word track to the href, but not the dates or the .html

  11. #11
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace
    Code:
        LinkObj.href = LinkObj;
    with the line I posted.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  12. #12
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers Dale, worked perfectly!

  13. #13
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops....1 more thing,

    I need it to point to a directory like this:

    year/month/day/track.....etc.

    How would I do this?

  14. #14
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its ok - I worked it out.

    thanks,
    Martin


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
  •