By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,460 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,460 IT Pros & Developers. It's quick & easy.

Auto insert Date in form input field

P: n/a
I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.

Any help would be appreciated.

Doug
Jul 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Lee
Dwalker said:

I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.


<html>
<head>
<script type="text/javascript">
function zp(n){
return n<10?("0"+n):n;
}
function insertDate(t,format){
var now=new Date();
var DD=zp(now.getDate());
var MM=zp(now.getMonth()+1);
var YYYY=now.getFullYear();
var YY=zp(now.getFullYear()%100);
format=format.replace(/DD/,DD);
format=format.replace(/MM/,MM);
format=format.replace(/YYYY/,YYYY);
format=format.replace(/YY/,YY);
t.value=format;
}
</script>
</head>
<body>
<form>
<input onfocus="insertDate(this,'MM/DD/YYYY')"><br>
<input onfocus="insertDate(this,'MM/DD/YY')"><br>
<input onfocus="insertDate(this,'DD/MM')"><br>
<input onfocus="insertDate(this,'YYYY-MM-DD')"><br>
</form>
</body>
</html>

Jul 20 '05 #2

P: n/a

"Lee" <RE**************@cox.net> wrote in message
news:bk********@drn.newsguy.com...
Dwalker said:

I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.


<html>
<head>
<script type="text/javascript">
function zp(n){
return n<10?("0"+n):n;
}
function insertDate(t,format){
var now=new Date();
var DD=zp(now.getDate());
var MM=zp(now.getMonth()+1);
var YYYY=now.getFullYear();
var YY=zp(now.getFullYear()%100);
format=format.replace(/DD/,DD);
format=format.replace(/MM/,MM);
format=format.replace(/YYYY/,YYYY);
format=format.replace(/YY/,YY);
t.value=format;
}
</script>
</head>
<body>
<form>
<input onfocus="insertDate(this,'MM/DD/YYYY')"><br>
<input onfocus="insertDate(this,'MM/DD/YY')"><br>
<input onfocus="insertDate(this,'DD/MM')"><br>
<input onfocus="insertDate(this,'YYYY-MM-DD')"><br>
</form>
</body>
</html>

Jul 20 '05 #3

P: n/a
JRS: In article <wR******************@bignews3.bellsouth.net>, seen in
news:comp.lang.javascript, Dwalker <dl*******@hotmail.com> posted at
Thu, 25 Sep 2003 13:47:05 :-
I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.


That format should nor be used on the World-Wide Web; since only a few
countries use it, it is generally misleading (as is dd/mm/yyyy, of
course).

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #4

P: n/a
Ivo

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:ro**************@merlyn.demon.co.uk...
JRS: In article <wR******************@bignews3.bellsouth.net>, seen in
news:comp.lang.javascript, Dwalker <dl*******@hotmail.com> posted at
Thu, 25 Sep 2003 13:47:05 :-
I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.


That format should nor be used on the World-Wide Web; since only a few
countries use it, it is generally misleading (as is dd/mm/yyyy, of
course).


Things became confusing only after the colonists in the New World went
looking for an identity in spelling anomalies.
No 'countries' that I know of use the format yyyy/mm/dd although that is the
one which sorts alphabetically and chronologically simultaneously. Or would
you suggest using the Julian Day Number?
Ivo
Jul 20 '05 #5

P: n/a
Lee
Dr John Stockton said:

JRS: In article <wR******************@bignews3.bellsouth.net>, seen in
news:comp.lang.javascript, Dwalker <dl*******@hotmail.com> posted at
Thu, 25 Sep 2003 13:47:05 :-
I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.


That format should nor be used on the World-Wide Web; since only a few
countries use it, it is generally misleading (as is dd/mm/yyyy, of
course).


Curiosity: How widely accepted is yyyy-mm-dd out there in the Rest of
The World? In addition to software development, I've been using it on
bank drafts and forms for several months, but have never spotted it in
the wild (USA-AZ).

Jul 20 '05 #6

P: n/a
JRS: In article <bl*********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Fri,
26 Sep 2003 10:26:22 :-
Dr John Stockton said:

JRS: In article <wR******************@bignews3.bellsouth.net>, seen in
news:comp.lang.javascript, Dwalker <dl*******@hotmail.com> posted at
Thu, 25 Sep 2003 13:47:05 :-
I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.


That format should nor be used on the World-Wide Web; since only a few
countries use it, it is generally misleading (as is dd/mm/yyyy, of
course).


Curiosity: How widely accepted is yyyy-mm-dd out there in the Rest of
The World? In addition to software development, I've been using it on
bank drafts and forms for several months, but have never spotted it in
the wild (USA-AZ).


It is, I have been lead to understand, a US Federal Standard.
USA Standard: ANSI X3.30-1985(R1991), FIPS PUB 4-1, 4-2.
if you indulge in foreign travel, it is also
Canada: CAN/CSA-Z234.5-89. (Z234-4 ?)
and many others.
It matters not, however, how widely it is used, but how widely it is
understood correctly.

My Bank have remarked (audibly) on seeing it, but have understood it and
accepted it without demur.

A date in MM/DD/YYYY, such as Jan 4th, being written as 01/04/2004, will
be understood throughout Europe as meaning April Fools Day. The date of
Remembrance Sunday, written demotically in the UK as 09/11/2003, will be
misunderstood by Americans.

But everyone can understand 2004/04/11 as being the coming Easter
Sunday, given an adequate 2004 diary.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #7

P: n/a
JRS: In article <3f*********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Fri, 26 Sep 2003
19:43:42 :-

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:ro**************@merlyn.demon.co.uk...
JRS: In article <wR******************@bignews3.bellsouth.net>, seen in
news:comp.lang.javascript, Dwalker <dl*******@hotmail.com> posted at
Thu, 25 Sep 2003 13:47:05 :-
>I just want to enter today's date in a text input box with the format
>mm/dd/yyyy when it receives focus.
That format should nor be used on the World-Wide Web; since only a few
countries use it, it is generally misleading (as is dd/mm/yyyy, of
course).


Things became confusing only after the colonists in the New World went
looking for an identity in spelling anomalies.


Any responsibility that the UK may have for this must be shared in part
with the country that founded New Amsterdam. It is one thing, I
suspect, for which the French need not be blamed.
No 'countries' that I know of use the format yyyy/mm/dd although that is the
one which sorts alphabetically and chronologically simultaneously.
I believe Japan and China use it routinely. MSDOS 5 believes that YYYY-
MM-DD is also used in French Canada, Hungary, Czechoslovakia, Sweden,
Yugoslavia, Poland.
Or would
you suggest using the Julian Day Number?


No, not least because the Julian Day Number does not define a Civil
Date. Modified JD defines a UK Civil Date (ignoring Summer Time); and
Chronological JD & CMJD define a civil date anywhere.

For more, see via below.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #8

P: n/a
Dr John Stockton wrote on 28 sep 2003 in comp.lang.javascript:
But everyone can understand 2004/04/11 as being the coming Easter
Sunday, given an adequate 2004 diary.


In 2004 everywhere, but:

"The Orthodox Easter usually falls later than the Catholic Easter,
depending on when Passover is. The Russian Easter falls one week after
Passover."

Year 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

Catholic 23/4 15/4 31/3 20/4 11/4 27/3 16/4 8/4 23/3 12/4 4/4
Orthodox 30/4 15/4 5/5 27/4 11/4 1/5 23/4 8/4 27/4 19/4 4/4
John, as a numbercruncher you will like this, I hope:

<http://www.assa.org.au/edm.html>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #9

P: n/a
JRS: In article <Xn********************@194.109.133.29>, seen in
news:comp.lang.javascript, Evertjan. <ex**************@interxnl.net>
posted at Sun, 28 Sep 2003 21:01:17 :-
Dr John Stockton wrote on 28 sep 2003 in comp.lang.javascript:
But everyone can understand 2004/04/11 as being the coming Easter
Sunday, given an adequate 2004 diary.
In 2004 everywhere, but:

"The Orthodox Easter usually falls later than the Catholic Easter,
depending on when Passover is. The Russian Easter falls one week after
Passover."

Year 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

Catholic 23/4 15/4 31/3 20/4 11/4 27/3 16/4 8/4 23/3 12/4 4/4
Orthodox 30/4 15/4 5/5 27/4 11/4 1/5 23/4 8/4 27/4 19/4 4/4


Not only "Catholic", but also "Protestant"; or, to give due credit,
"Gregorian". The first row agrees with Zeller & other sources.

But, while I have reliable algorithms for Julian Easter, I have nothing
that gives the Orthodox row of dates. Is that Passover the Pesach of
the accepted Hebrew calendar, or is it some rival computation?

Hebrew Pesach is 15 Nisan, and the Hebrew Year rotates slowly against
the Gregorian; so, if it is the same Pesach, the attached Easter will
not remain with Gregorian April/May. OTOH, neither will remain forever
in accord with the actual seasons.
John, as a numbercruncher you will like this, I hope:
<http://www.assa.org.au/edm.html>

Will look.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.