...

View Full Version : how can I make a dynamic date and time into form ?



kee
08-23-2004, 09:01 PM
I would like to know how can I make a dynamic time (2:58:08 AM) and date (dd/mm/yyyy) into a form like textfield.the date will auto increasing like
2:58:08 AM
2:58:09 AM
2:58:10 AM
2:58:11 AM

I have a script to show the time already (no date scipt yet) but I can't put it into the textfield. I'm not good in Java Script.

Then, when we submit a form , it will send the current value of date and time to a program to do some works.

Thank you
Kee

A1ien51
08-24-2004, 02:01 AM
just set the form value with the time script you have....

document.FormName.ElementName.value = theTimeVariable

Eric

kee
08-24-2004, 04:10 AM
Now, I can do it. I have a two text field. The first is time text field, and date text field. the problem is that I can't invoke both of date and time.
my code is following :


<script language="javascript">

var my12_hour = 1;
var dn = "";

function show_clock()
{
var Digital = new Date();
var hours = Digital.getHours();
var minutes = Digital.getMinutes();
var seconds = Digital.getSeconds();

if (my12_hour) {
dn = "AM";
if (hours > 12) { dn = "PM"; hours = hours - 12; }
if (hours == 0) { hours = 12; }
} else {
dn = "";
}
if (minutes <= 9) { minutes = "0"+minutes; }
if (seconds <= 9) { seconds = "0"+seconds; }

myclock = hours+':'+minutes+':'+seconds+' '+dn;

document.kee.time.value = myclock;

setTimeout("show_clock()",1000);
}
function show_date()
{
today = new Date () ;
Year=today.getYear();
if (Year < 1000)
Year+=1900 + 543
Date=today.getDate();

document.kee.date.value = Date + "/" + today.getMonth()+"/"+Year+""
}
</script>


then , I used "<BODY onLoad="show_clock(), show_date()">". It makes the clock textfield don't increase the time. How can I fix them ?

Thank you
Kee

glenngv
08-24-2004, 05:26 AM
You need to separate function calls with semicolon not comma.
But you can make it as a single function by just including the date part in the show_clock() function.

Change this line:

document.kee.time.value = myclock;

to:

document.kee.time.value = Digital.getDate() + "/" + (Digital.getMonth()+1) + "/" + Digital.getFullYear() + " " + myclock;

and then onload:

<BODY onLoad="show_clock()">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum