Display Date in Text Box on ASP page

T

tsmith81

Ok. I have an ASP page that send data to a database. One of the fields
is "Date" (no quotes). The form name is FrontPage_Form1. I would like
the Date field to auto populate. So, I did some research and the only
thing that I could come up with that worked was this:

<script>
function upDate() {
FrontPage_Form1.Date.value=new Date();



}

setInterval('upDate()',1000);
</script>


While this is good, I need the date to be displayed as MM/DD/YY or
MM/DD/YYYY. Help me please....

Thanks in advance,

Tim
 
L

Lee

(e-mail address removed) said:
Ok. I have an ASP page that send data to a database. One of the fields
is "Date" (no quotes). The form name is FrontPage_Form1. I would like
the Date field to auto populate. So, I did some research and the only
thing that I could come up with that worked was this:

<script>
function upDate() {
FrontPage_Form1.Date.value=new Date();



}

setInterval('upDate()',1000);
</script>


While this is good, I need the date to be displayed as MM/DD/YY or
MM/DD/YYYY. Help me please....

Since this is an ASP page, you should be filling in the date
in your ASP code on the server side, where you know that
scripting is enabled and that the system clock is set to the
correct year.
 
T

tsmith81

Forgive my ignorance at the moment... I have been searching for my
answer to this for 8 hours. Can you tell me how I can do this? Thank
you.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Tue, 10 May 2005 13:57:42, seen in (e-mail address removed) posted :
Ok. I have an ASP page that send data to a database. One of the fields
is "Date" (no quotes). The form name is FrontPage_Form1. I would like
the Date field to auto populate. So, I did some research and the only
thing that I could come up with that worked was this:

<script>
function upDate() {
FrontPage_Form1.Date.value=new Date();



}

setInterval('upDate()',1000);
</script>


While this is good, I need the date to be displayed as MM/DD/YY or
MM/DD/YYYY. Help me please....

It's less good than you think, unless you have omitted relevant
information, since the text string format obtained that way is not well
defined.

Only chronologically backward locations still use FFF dates; it is
recommended that ISO 8601 / ANSI X3.30-1985(R1991), FIPS PUB 4-1, 4-2
be followed. Use YYYY-MM-DD or YYYY/MM/DD, in order that there can be
no misunderstanding.

Note that setInterval(..., 1000) does not necessarily update every
second. However, one can get an update every second (unless the client
CPU is pre-empted) by using setTimeout(..., X), see via below.

If you need to know the date and time by the client computer, can you
not get it loaded into ...Date.value as part of the Submit process? If
you only need the correct date and time, that's better done on the
server - though the possible consequences of using a date and time that
the user may think are wrong should be considered.

One should read a newsgroup's FAQ before posting. See below.
 
T

Thomas 'PointedEars' Lahn

(e-mail address removed) wrote:
^^^^^^^^^^^^^^^^^^
You want to refrain from spoiling namespaces:
Try this (works on my form)

// Right after body tag

Not required. The first snippet may be located anywhere before the
second snippet is parsed. ASP does not care if it is HTML or FUBAR
you are sending to the client.
<%
dim todaysDate

todaysDate = date()
%>



// Form Field

<input type="text" name="tDate" size="25" value="<%=todaysDate %>">
^^^^^^^^^^^
not necessary, it's the default

Works with VBScript. As this is a J(ava)Script/ECMAScript group,
here's the JScript ASP solution (probably without any user-defined
date formatting as well):

<%@ LANGUAGE = "JScript" %>
<%
var todaysDate = Date();
%>
...
<input name="tDate" size="25" value="<%= todaysDate %>">


PointedEars
 

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
474,434
Messages
2,571,688
Members
48,796
Latest member
Greg L.

Latest Threads

Top