SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    displaying todays date in dropdown menu

    hello All

    i was wandering id you could help me

    i have this drop down menu

    &nbsp;<select name="cdate" id="cdate" onchange="changedate()">
    <option>Date</option>
    <option value="n">No date</option>
    <option value="a">2nd April 2006</option>
    <option value="b">2 April 2006</option>
    <option value="c">2nd Apr 2006</option>
    <option value="d">2 Apr 2006</option>
    <option value="e">02/04/2006</option>
    <option value="f">2nd April 06</option>
    <option value="g">2 April 06</option>
    <option value="h">2nd Apr 06</option>
    <option value="i">2 Apr 06</option>
    <option value="j">02/04/06</option>
    <option value="k">2nd April</option>
    <option value="l">2 April</option>
    <option value="m">2nd Apr</option>
    <option value="o">2 Apr</option>
    <option value="p">02/04</option>
    </select>

    can i make it change the date dynamic, so when its todys date it will show it in the drop down list in the above format.

    at the moment if you click on the options above it will show the date on the format for example 2nd Apr 2006 it will show 5th april 2006, so it works but it displays the 2nd instead as i started the application on than.

    any ideas

    thanks

  2. #2
    Chive On FFCus's Avatar
    Join Date
    Feb 2006
    Location
    Connecticut
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using plain HTML, or is it PHP, ASP, JSP, .NET, etc.?

    It could be done with Javascript, but I think it is much better to perform the dynamic rendering on the server side (if possible) in this case.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i,m using php for server side

    i just basicaly need it to display todays date rather than the labels you see above

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you understand i mean

  5. #5
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i,m using this to alter how the time is displayed, this doesnt need to update is just to choose how you want the time displayed.

    <select name="ctime" id="ctime" onchange="changetime()">
    <option value=""></option>
    <option value="n">No Time</option>
    <option value="a">am/pm with seconds</option>
    <option value="b">am/pm without seconds</option>
    <option value="c">12h with seconds</option>
    <option value="d">12h without seconds</option>
    <option value="e">24h with seconds</option>
    <option value="f">24h without seconds</option>

    </select>

  6. #6
    Chive On FFCus's Avatar
    Join Date
    Feb 2006
    Location
    Connecticut
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You always want the select options to show the actual date in the different formats, right?

  7. #7
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exactly

  8. #8
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any ideas?

  9. #9
    Chive On FFCus's Avatar
    Join Date
    Feb 2006
    Location
    Connecticut
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not a PHP expert by any means, but I would image it has plenty of abilities to obtain date parts. Most languages do. Having said that, in my PHP code I would dynamically write each line of the select options

    Code:
    <option value="a">2nd April 2006</option>
    <option value="b">2 April 2006</option>
    <option value="c">2nd Apr 2006</option>
    <option value="d">2 Apr 2006</option>
    <option value="e">02/04/2006</option>
    <option value="f">2nd April 06</option>
    <option value="g">2 April 06</option>
    <option value="h">2nd Apr 06</option>
    <option value="i">2 Apr 06</option>
    <option value="j">02/04/06</option>
    <option value="k">2nd April</option>
    <option value="l">2 April</option>
    <option value="m">2nd Apr</option>
    <option value="o">2 Apr</option>
    <option value="p">02/04</option>
    to match the format I wanted.

    In .NET I can get the day, month number, month name year, etc. very easily. Maybe somebody with PHP knowledge can help out here.
    Last edited by FFCus; Apr 5, 2006 at 13:07. Reason: Fixed spelling error

  10. #10
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would you do it line by line?

    in my PHP code I would dynamically write each line of the select options

  11. #11
    Chive On FFCus's Avatar
    Join Date
    Feb 2006
    Location
    Connecticut
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by benq
    how would you do it line by line?

    in my PHP code I would dynamically write each line of the select options
    Yes, you will need to format each line as you go.

    In ASP Classic, it would be done by

    <option value="b"><%= Day(Date) & " " & MonthName(Month(Date)) & " " & Year(Date) %></option>

    This would display "5 April 2006", assuming it was viewed today!

    You will have to format each line as needed for the display you desire.


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
  •