Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time spent completing a form 2

Status
Not open for further replies.

Antonimo

Technical User
Jun 26, 2003
86
SE
I would like to include a javascript timer that will return the amount of time spent by a visitor on a page.

It will be used to measure how much time it takes for the visitor to complete a form so it needs to be included in the information that is sent.

Please, can anybody help me or point me to an existing script?
 
Capture the epoch time (which is in seconds) when the page loads. Add an onSubmit script which again captures the epoch time; subtract the original captured value from this to get the time spent editing and store the result into a hidden field value, then complete the submission.
 
Thanks for the reply MOrac,

I understand the principle of what you are saying, however, I am just a beginner with JavaScript and I don't know how to actually "write" it :-(

Can anyone help me a little more, plase?
 
This will store the milliseconds needed to complete the page

Code:
<body onLoad="startTime = new Date()" onUnload="endTime = new Date(); document.myForm.timerField.value = endTime.valueOf() - startTime.valueOf()">

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
zen.gif

 
Then I add the following to the form within the web page...

<input name="timerField" type="hidden">

Thank you to MOrac and mwolf00

This works beautifully :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top