473,385 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Auto insert Date in form input field

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

"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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
4
by: the hotshot | last post by:
hello, this seems to be a hard question so far and noone has been able to help with this. is it possible to have access start an autonumber with a prefix according to the year when the data is...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
6
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
6
by: awojciehowski | last post by:
I am working with a database now and need some guidance. I am attempting to input an auto calculation. I have the ability to enter a date in a text box on a form. I want to be able to have...
6
by: ndeeley | last post by:
Hi, How do I insert a null or blank field into a database using coldfusion? I'm new to CF and its proviing a bit tricky! My database date field accepts null values (I think - theres no default...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: brianrpsgt1 | last post by:
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.