Initialize date to today

Discussion in 'HTML' started by Darth Ferret, Oct 28, 2003.

  1. Darth Ferret

    Darth Ferret Guest

    I have text fields on a form I created in dreamweaver. I use a javascript
    function for form validation.

    I would like to initialize a date field to todays date, and allow them to
    change it if they want. Can someone tell me how to do this?

    Thanks in advance,
    Joe
     
    Darth Ferret, Oct 28, 2003
    #1
    1. Advertising

  2. Darth Ferret

    Chris Morris Guest

    "Darth Ferret" <> writes:
    > I have text fields on a form I created in dreamweaver. I use a javascript
    > function for form validation.
    >
    > I would like to initialize a date field to todays date, and allow them to
    > change it if they want. Can someone tell me how to do this?


    There's no 'date field' type in HTML, so how are you allowing input of
    the date? (e.g. <select>s for day/month/year, or an <input
    type="text"...> for free-form date entry, or ...)

    Possibly best to do this server side - it's fairly easy to write a
    function in PHP (and I assume similarly easy in ASP/JSP/etc) that
    creates <select>s for day, month and year, and puts
    selected="selected" in the <option>s for the current date.

    Trying to get the time client side is riskier - you can run NTP on a
    server and be fairly sure the time is right, whereas client computers
    could have the time set completely wrong. And then there's time zone
    differences to think about...

    --
    Chris
     
    Chris Morris, Oct 28, 2003
    #2
    1. Advertising

  3. Darth Ferret wrote:

    > I would like to initialize a date field to todays date, and allow them to
    > change it if they want. Can someone tell me how to do this?


    In PHP:

    <fieldset>
    <legend>Date</legend>
    <input id="dd" name="dd" maxlength="2" size="2" type="text"
    value="<?php echo date('d'); ?>">
    <input id="mm" name="mm" maxlength="2" size="2" type="text"
    value="<?php echo date('m'); ?>">
    <input id="yyyy" name="yyyy" maxlength="2" size="2" type="text"
    value="<?php echo date('Y'); ?>">
    <label for="dd" title="Day">dd</label>/<label for="mm"
    title="Month">mm</label>/<label for="yyyy" title="Year">yyyy</label>
    </fieldset>

    Of course, this requires that your host supports PHP.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?id=132
     
    Toby A Inkster, Oct 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TN Bella
    Replies:
    5
    Views:
    377
    Patrick Steele [MVP]
    Jun 18, 2004
  2. TB
    Replies:
    0
    Views:
    454
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,278
    Michael Borgwardt
    May 30, 2004
  4. Vinnie Davidson

    ASP Date: get records with date = today (SQL Server)

    Vinnie Davidson, Aug 13, 2005, in forum: ASP General
    Replies:
    6
    Views:
    327
    Aaron Bertrand [SQL Server MVP]
    Aug 15, 2005
  5. joeyej
    Replies:
    7
    Views:
    151
    Randy Webb
    Apr 6, 2006
Loading...

Share This Page