Putting date and time in input feild of form?!?!

S

Shaiboy_UK

Hi all,

Hopefully something simple here.

I have written a form that takes data from a text box and updates it into an
Access database. However, I want to also pass the local user date and time
using date() and time() JavaScript commands, but can't find the right syntax
to put them in the input command, example:
<input name=date value="<javascript command here">

Can anyone help?

Thanks in advance.

Cheers
Shaiboy_UK
 
M

Mick White

Shaiboy_UK said:
Hi all,

Hopefully something simple here.

I have written a form that takes data from a text box and updates it into an
Access database. However, I want to also pass the local user date and time
using date() and time() JavaScript commands, but can't find the right syntax
to put them in the input command, example:
<input name=date value="<javascript command here">
<body onload="document.forms[0].date.value=new Date()">
....
<input name=date type="text">

Mick
 
L

Lee

Mick White said:
Shaiboy_UK said:
Hi all,

Hopefully something simple here.

I have written a form that takes data from a text box and updates it into an
Access database. However, I want to also pass the local user date and time
using date() and time() JavaScript commands, but can't find the right syntax
to put them in the input command, example:
<input name=date value="<javascript command here">
<body onload="document.forms[0].date.value=new Date()">
...
<input name=date type="text">

But realize that this is the date and time as set on the visitor's
desktop, which may have no relationship to reality. In fact, the
time reported by the browser may not even match what the visitor sees
on their desktop.
 
M

Mick White

Lee said:
Mick White said:
<body onload="document.forms[0].date.value=new Date()">
...
<input name=date type="text">


But realize that this is the date and time as set on the visitor's
desktop, which may have no relationship to reality. In fact, the
time reported by the browser may not even match what the visitor sees
on their desktop.

True...
Mick
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Fri, 14 Jan 2005 14:07:18, seen in Mick White
Shaiboy_UK wrote:

Could be because neither date() nor time() exists.
to put them in the input command, example:
<input name=date value="<javascript command here">
<body onload="document.forms[0].date.value=new Date()">
...
<input name=date type="text">

IMHO, while "date" is a perfectly legal name, it's not an ideal choice,
since it is too near "Date" to be typo-proof. "Today" would seem
better.

The date that goes into the Access database must be in a format that
Access considers appropriate; it's dangerous to assume that new Date(),
in any locality, will give a form that Access will accept specifically;
IIRC, the format of DateObj.toString() is not actually defined.

Note : the OP is in UK, his application may be UK or wider. Sometimes,
though localised to UK, browsers give FFF dates; sometimes, though in
UK, browsers are not localised to UK (in our Public Library, last time I
looked, localisation was US; but most users might have preferred KR).

I don't know what Access can accept, with/without localisation; give the
date/time in ISO 8601:2004 if possible - YYYY-MM-DD hh:mm:ss; or
YYYY/MM/DD hh:mm:ss. Do not rely, except maybe on an intranet, on any
formats offered by javascript; build what you want in a localisation-
proof manner, unless you are satisfied that both products will always
localise compatibly.

See below.
 
S

Shaiboy_UK

Mick White said:
<html>
<body onload="document.forms[0].date.value=new Date()">
<form>
<input type="text" name="date">
</form>
</html>

It's preferable to use "new Date()", rather than "Date()" as you have.
Mick

Hi Mick,

Any way I could get the date and time in two boxes in the format of:
DD/MM/YY and HH:MM ? like in this format??
<input type="text" name="date">
<input type="text" name="time">

Thanks for this.

Cheers
Shaiboy_UK
 
S

Shaiboy_UK

Mick White said:
<body
onload='with(document.forms[0]){date.value=the.date;time.value=the.time}'>
<form>
<input type="text" name="date">
<input type="text" name="time">
</form>


<script type="text/JavaScript">
d=new Date()
the= {
date:d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear(),
time:d.getHours()+":"+d.getMinutes()
}

</script>

Mick

Thanks Mike,

Cheers
Shaiboy_UK
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top