473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

document.form.fieldname.value=

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
5 2660
gits
5,390 Expert Mod 4TB
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
Hi..

That's exactly what I want to do -

document.myform.dateandtime.value = ??

Many thanks
GeeItsBee
Oct 29 '07 #3
gits
5,390 Expert Mod 4TB
:) 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
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
5,390 Expert Mod 4TB
hi ...

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

kind regards
Oct 30 '07 #6

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

Similar topics

3
by: Alex | last post by:
This may sound like a simple question but I really dont' know how to do this. I know you can call a Form Variable in a VBscript using Request.Form("FieldName") and make equal a local variable...
2
by: Colin Steadman | last post by:
Part No Description Quantity 45643 Random part 10 45678 Another Random part 7 98944 And another 1 <submit button> ...
3
by: jason | last post by:
I have a function that <body onload=..> sets some form values. However when i execute that functionf from external js file, i get erorrs and it dont work. The function sets the fields via ...
1
by: Hellp | last post by:
I have a non-asp page with a form as follows: <FORM action='FormPost.aspx' method=post encType=text/plain> <INPUT type=hidden value=" GHT Tankage"> <INPUT size=6 name=2977_> <INPUT size=40...
11
by: dkate777 | last post by:
Hi, Is anybody know how to pass textbox input value to another page. I am using document.secondform.fieldname.value=document.firstformname.fieldname.value but it's not working Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.