- Link the external javascript file into header
<head>
<script type="text/javascript" src="js/clock.js"></script>
</head> - load the function getSecs() from javascript file using setTimeout
<body onload="window.setTimeout('getSecs()',1)"> - copy the following code into js/clock.js file:
- <!-- Begin
- startday = new Date();
- clockStart = startday.getTime();
- function initStopwatch()
- {
- var myTime = new Date();
- return((myTime.getTime() - clockStart)/1000);
- }
- function getSecs()
- {
- var tSecs = Math.round(initStopwatch());
- var iSecs = tSecs % 60;
- var iMins = Math.round((tSecs-30)/60);
- var sSecs ="" + ((iSecs > 9) ? iSecs : + iSecs);
- var sMins ="" + ((iMins > 9) ? iMins : + iMins);
- document.getElementById("timespent").value = sMins+":"+sSecs;
- var duration = QueryString("Duration");
- if(sMins>=duration)
- window.location="http://localhost/eLearning/examNotice.php";
- window.setTimeout('getSecs()',1000);
- QueryString("CourseID");
- }
- // End -->
- function QueryString(key)
- {
- //Get the full querystring
- fullQs = window.location.search.substring(1);
- //Break it down into an array of name-value pairs
- qsParamsArray = fullQs.split("&");
- //Loop through each name-value pair and
- //return value in there is a match for the given key
- for (i=0;i<qsParamsArray.length;i++) {
- strKey = qsParamsArray[i].split("=");
- if (strKey[0] == key) {
- return strKey[1];
- }
- }
- }
Sunday, 29 April 2012
Clock Stopwatch Timeout event
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment