By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,043 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,043 IT Pros & Developers. It's quick & easy.

document.form.fieldname.value=

P: 7
I am sure this is relatively simple, but I am new to js and would appreciate some help in getting the following sorted.

I use the following in a hidden form field - onsubmit="stamp" which successfully inserts the dateandtime GMT date string into a pearl cgi template server-side.

Expand|Select|Wrap|Line Numbers
  1. function stamp() {
  2.     document.myform.dateandtime.value = (new Date).toUTCString();
  3. }
  4.  
However, I needed a more precise method of date stamping the message and have constructed the ISO date script below which writes a descending number starting with the full year down to milliseconds e.g.

20071029081534876

Expand|Select|Wrap|Line Numbers
  1. var today = new Date()
  2.   var month = today.getUTCMonth()+1
  3.   var year = today.getUTCFullYear()
  4.   var day = today.getUTCDate()
  5.   var hour = today.getUTCHours()
  6.   var minute = today.getUTCMinutes()
  7.   var second = today.getUTCSeconds()
  8.   var msec = today.getUTCMilliseconds()
  9.  
  10.   if(month<10) month = "0" + month
  11.   if(day<10) day = "0" + day
  12.   if(hour<10) hour = "0" + hour
  13.   if(minute<10) minute = "0" + minute
  14.   if(second<10) second = "0" + second
  15.   if(msec<100) msec = "0" + msec
  16.   if(msec<10) msec = "00" + msec
  17.  
  18.   var nowTime = (year + '' + month + '' + day + '' + hour + '' + minute + '' + second + '' + msec)
  19.  
  20.   document.write(nowTime);
  21.  
My problem is; how do I use the DOM to get it to write as per my original script??

Any help appreciated
GeeItsBee
Oct 29 '07 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

welcome to TSDN ...

so i think you want the timestamp that you created to be the value of the hidden field like in your first example?

kind regards
Oct 29 '07 #2

P: 7
Hi..

That's exactly what I want to do -

document.myform.dateandtime.value = ??

Many thanks
GeeItsBee
Oct 29 '07 #3

gits
Expert Mod 5K+
P: 5,390
:) ok ... let me give you an example:

Expand|Select|Wrap|Line Numbers
  1. function get_time_stamp() {
  2.     // your time-stamp-code here but instead of 
  3.     // document.write it put the following:
  4.  
  5.     return nowTime;
  6. }
  7.  
  8. function set_field_value() {
  9.     node_ref.value = get_time_stamp();
  10. }
kind regards
Oct 29 '07 #4

P: 7
Many thanks.

I've had a play and couldn't get it to work, then I saw the 'light'!

Expand|Select|Wrap|Line Numbers
  1. function stamp() {
  2.     document.myform.dateandtime.value = stampMe();
  3. }
  4.  
  5. function stampMe() {
  6.  
  7. // my script in here   
  8.  
  9.   return nowTime;
  10. }
I tried to make it harder than what it was!!
GeeItsBee
Oct 29 '07 #5

gits
Expert Mod 5K+
P: 5,390
hi ...

glad to hear you got it working :) ... post back to the forum anytime you have more questions ...

kind regards
Oct 30 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.