Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Initialize date to today

Reply
Thread Tools

Initialize date to today

 
 
Darth Ferret
Guest
Posts: n/a
 
      10-28-2003
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


 
Reply With Quote
 
 
 
 
Chris Morris
Guest
Posts: n/a
 
      10-28-2003
"Darth Ferret" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Toby A Inkster
Guest
Posts: n/a
 
      10-29-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Notice the date today? What happened 40 years ago today? richard Computer Support 10 07-29-2009 08:20 PM
popup date picker cannot choose today's date TB ASP .Net 0 03-16-2006 01:37 PM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
ASP Date: get records with date = today (SQL Server) Vinnie Davidson ASP General 6 08-15-2005 07:28 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments