The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Timer on perl-cgi generated page
Discuss Timer on perl-cgi generated page in the Perl Programming forum on Dev Shed. Timer on perl-cgi generated page Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 4th, 2000, 04:02 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: Pennsylvania, USA
Posts: 37
Time spent in forums: 24 m 15 sec
Reputation Power: 14
|
|
|
I need the ability to place a timer on a page that will be generated from a cgi-script. I've found timer javascript routines, which I could imbed into the perl but with my limited javascript knowledge - I don't know if I'll be able to capture the time when the user leaves the page.
Basically, I need the timer to not only display, but allow me to capture the elapsed time and update a database with it.
Has anyone done something like this, or can anyone give me some advice on the best way to accomplish this?
Thanks!
Sharon
|

May 4th, 2000, 07:14 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
You can place a timestamp of which when the perl script is executed. But you can't capture the time when your visitor leaves the page since your script doesn't get executed anymore by doing so.
However, you can capture the timestamp for the next visit of that particular visitor by using cookie. PHP does a better job than Perl in this case.
|

May 5th, 2000, 10:05 AM
|
|
Contributing User
|
|
Join Date: May 2000
Posts: 179
Time spent in forums: 1 h 37 m 38 sec
Reputation Power: 14
|
|
|
you can use the event handlers Onload and onUnload to capture the time the user loads a page and the time a user leaves the page. Afterwards, subtract the two times to find out how long the user was on the page.
You can hold this value in a hidden form element and send it via cgi to your database.
You'll need to become acquainted with the Date method in JavaScript.
Hope this helps you get closer to your solution.
|

May 5th, 2000, 01:48 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: Pennsylvania, USA
Posts: 37
Time spent in forums: 24 m 15 sec
Reputation Power: 14
|
|
|
This sounds like a good solution, although I guess I would do this in addition to actually placing the javascript code there to show the representation of the incrementing time on the screen while they're visiting (a small clock window at the top of the page). My limited experience with javascript is still causing me a problem with this approach, however - how do I get the value from the calculation (difference between load and unload times) into the hidden form field in order to pass it to the cgi-script?
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by mcsimon:
you can use the event handlers Onload and onUnload to capture the time the user loads a page and the time a user leaves the page. Afterwards, subtract the two times to find out how long the user was on the page.
You can hold this value in a hidden form element and send it via cgi to your database.
You'll need to become acquainted with the Date method in JavaScript.
Hope this helps you get closer to your solution.[/quote]
|

May 5th, 2000, 06:59 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>you can use the event handlers Onload and onUnload to capture the time the user loads a page and the time a user leaves the page
You really can't with onUnload. The script doesn't get executed. Once you left the page, you no longer with it.
>>how do I get the value from the calculation
Let your cgi script do this dirty work.
>>into the hidden form field in order to pass it to the cgi-script
You have to make a form submit button with "Click here to Leave", then the hidden field can be passed to the script. If the visitor doesn't click it, the time can't be captured.
########################################
Take a look at this under "Date & Time" link.. http://www.essex1.com/people/timothy/js-index.htm
|

May 6th, 2000, 02:10 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
<<<You have to make a form submit button with "Click here to Leave", then the hidden field can be passed to the script. >>>
I think this is the viable solution for solving smmorrow's problem.
------------------
SR -
shiju.dreamcenter.net
|

May 8th, 2000, 07:43 AM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: Pennsylvania, USA
Posts: 37
Time spent in forums: 24 m 15 sec
Reputation Power: 14
|
|
|
I already have a button on the page that the visitor clicks to move on to the next page. I can use this to 'stop the clock' and submit the form to the cgi-script. So, combining the unLoad to start the clock and the onClick to stop it, I should have what I need to time the visitor.
I know I'm missing something due to my inexperience with javascript - but my main question remains: how do I get the value of a javascript variable into a form field for passing to a cgi-script?
smmorrow
|

May 8th, 2000, 11:14 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
If you take a look at http://www.essex1.com/people/timothy/js-index.htm under Date & Time, you should see..
<INPUT TYPE="text" NAME="local" SIZE=16 VALUE="Current Time">
>>how do I get the value of a javascript variable into a form field for passing to a
cgi-script?
As you can see that form field name is "local" but the form is <form> instead of <form method="POST" action="/cgi-bin/script.pl">
So it's all up to your script.pl to handle the value of "local" from your 'time page' and pass it onto the next page.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|