Initialize date to today

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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,

Re: Initialize date to today

Quoted text here. Click to load it

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...


Re: Initialize date to today

Darth Ferret wrote:

Quoted text here. Click to load it


  <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>

Of course, this requires that your host supports PHP.

Toby A Inkster BSc (Hons) ARCS
Contact Me -

Site Timeline