Initialize date to today

D

Darth Ferret

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
 
C

Chris Morris

Darth Ferret said:
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...
 
T

Toby A Inkster

Darth said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top