Time stamp on HTML form submittal

J

James Bond 007

I am a novice to Javascript
(can do simple text-based pop-ups,
but not familiar with variable manipulation).

I would like to have a Javascript that gives
me the start time (I don't care about the date)
when the user entered my webpage
and then the time that the user hit the "Submit" button
on my HTML form.

For example, my current HTML form e-mails
the following to me when the user hits "Submit"
(these are just sample lines):

NAME = James Bond
CITY = New York

Obviously, the user entered the above values
in a text widget that was on my webpage.

I'd like to add to the above something like the following,
but without the user having to do anything other
than hit the "Submit" button:

START_TIME = 12:05pm
END_TIME = 12:10pm

The "START_TIME" would be the time that the user
first entered my webpage, while the "END_TIME"
would be the time that the user hit the "Submit" button
on that same webpage (I can't rely on the e-mail timestamp
for the "END_TIME", because there may be internet delays
which would screw up my results).

If you supply a script, you needn't give too much detail/comments
(I'm a computer programmer with over 25 years of experience,
but only 5+ years as a novice HTML programmer),
as long as you show all the necessary code lines.
If 24-hour time would be easier, then that's fine, too.

Any help would be greatly appreciated.

Thanks!




-----
Bond . . . James Bond


Do not reply via e-mail.
The address is phony to prevent spam, etc.
Thank you for understanding.
 
M

Mick White

James said:
For example, my current HTML form e-mails
the following to me when the user hits "Submit"
(these are just sample lines):

NAME = James Bond
CITY = New York

Obviously, the user entered the above values
in a text widget that was on my webpage.

I'd like to add to the above something like the following,
but without the user having to do anything other
than hit the "Submit" button:

START_TIME = 12:05pm
END_TIME = 12:10pm


<body
onload="document.forms[0].elements['START_TIME'].value = new Date()">
<form...
onsubmit="this.elements['END_TIME'].value= new Date()">
<input name="START_TIME" type="hidden">
<input name="END_TIME" type="hidden">

....

</form>


Mick
 
J

James Bond 007

The result from your script gives the date AND time,
but that's fine; I can always parse out the non-time parts.

Thanks very much! : )


James said:
For example, my current HTML form e-mails
the following to me when the user hits "Submit"
(these are just sample lines):

NAME = James Bond
CITY = New York

Obviously, the user entered the above values
in a text widget that was on my webpage.

I'd like to add to the above something like the following,
but without the user having to do anything other
than hit the "Submit" button:

START_TIME = 12:05pm
END_TIME = 12:10pm


<body
onload="document.forms[0].elements['START_TIME'].value = new Date()">
<form...
onsubmit="this.elements['END_TIME'].value= new Date()">
<input name="START_TIME" type="hidden">
<input name="END_TIME" type="hidden">

...

</form>


Mick




-----
Bond . . . James Bond


Do not reply via e-mail.
The address is phony to prevent spam, etc.
Thank you for understanding.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 11 Nov
2004 08:24:41, seen in James Bond 007
The result from your script gives the date AND time,
but that's fine; I can always parse out the non-time parts.

Responses should go after trimmed quotes : see newsgroup FAQ.

If all relevant browsers give, as would be sensible, 24-hour time, then
replacing new Date() with String(new Date()).match(/\d\d:\d\d:\d\d/)
will do it - at least in my browser; it has just given 19:25:50 .
 
J

James Bond 007

(follow-up)

Here's how I re-arranged the script so that I would receive
only the start and end TIMES:

----------------
<HTML>

<HEAD></HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!-- hide from non-Java browsers

window.onload=function () {
var now=new Date(); // set the full date

// extract the START time for the user's time zone
document.forms[document.forms.length-1].START_TIME.value =
now.toLocaleTimeString();
}

// this is called when the user hits the "Submit" button
function ValidateTheForm() {
(do some validation stuff here)

var now=new Date(); // set the full date

// extract the END time for the user's time zone
document.forms[document.forms.length-1].END_TIME.value =
now.toLocaleTimeString();
}

// end hiding

</SCRIPT>

(etc)

<FORM NAME="NTRPTEST" METHOD="POST" ACTION="(CGI script)"
onSubmit="return ValidateTheForm()">

<INPUT TYPE="hidden" NAME="to" VALUE="(something)">
<INPUT TYPE="hidden" name="subject" VALUE="(something)">
<INPUT TYPE="hidden" NAME="form" VALUE="(something)">
<INPUT TYPE="hidden" NAME="admin" VALUE="(something else)">
(etc)
<!-- retrieve START & END times from Javascript, above,
-- and put result into submitted form without user knowing about it
-->
<INPUT TYPE="hidden" NAME="START_TIME">
<INPUT TYPE="hidden" NAME="END_TIME">
(etc)

<INPUT TYPE="submit" NAME="Submit" VALUE="SUBMIT">
(etc)
</FORM>

(etc)

</BODY>
</HTML>

----------
Here is an actual result that I got via e-mail
after the user hit the "Submit" button
(the user knows nothing about the times;
i.e., the user didn't have to touch or enter any values,
as far as that is concerned):

START_TIME = 10:04:39 AM
END_TIME = 10:21:31 AM

I will use these values to determine how long it takes
the user to fill-out the form; in this case, about 17 minutes!
(I probably could have done the calculation in the HTML,
but I want to know *when* they looked at the form, too!).

========================================================================
James Bond 007 wrote:

The result from your script gives the date AND time,
but that's fine; I can always parse out the non-time parts.

Thanks very much! : )


<body
onload="document.forms[0].elements['START_TIME'].value = new Date()">
<form...
onsubmit="this.elements['END_TIME'].value= new Date()">
<input name="START_TIME" type="hidden">
<input name="END_TIME" type="hidden">

...

</form>


Mick

James said:
For example, my current HTML form e-mails
the following to me when the user hits "Submit"
(these are just sample lines):

NAME = James Bond
CITY = New York

Obviously, the user entered the above values
in a text widget that was on my webpage.

I'd like to add to the above something like the following,
but without the user having to do anything other
than hit the "Submit" button:

START_TIME = 12:05pm
END_TIME = 12:10pm




-----
Bond . . . James Bond


Do not reply via e-mail.
The address is phony to prevent spam, etc.
Thank you for understanding.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top