Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2004, 09:01 PM   PM User | #1
kee
New to the CF scene

 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
kee is an unknown quantity at this point
Post how can I make a dynamic date and time into form ?

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
kee is offline   Reply With Quote
Old 08-24-2004, 02:01 AM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
just set the form value with the time script you have....

document.FormName.ElementName.value = theTimeVariable

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 08-24-2004, 04:10 AM   PM User | #3
kee
New to the CF scene

 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
kee is an unknown quantity at this point
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 :
Quote:
<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
kee is offline   Reply With Quote
Old 08-24-2004, 05:26 AM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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()">
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:03 PM.


Advertisement
Log in to turn off these ads.