Spency
11-23-2012, 08:41 AM
Good morning all!
I'm working with an html based quiz/test on logic, and I had a timer working for it but I'm having issues having the formail part of the script to message me the timer results. At the moment it messages me the start and finish time in full GMT Time format which, I can also use but I find it frustrating that I spent so much time trying to get a stopwatch to work in this script that now it won't message me the results of it.
Here are the two parts of the script I'm having issues with:
var c1, c2, c3, ID = null;
startTimer();
function startTimer() {
if (ID != null) {
stopTimer();
}
c1 = 0;
c2 = 0;
c3 = 0;
ID = window.setInterval(run, 100);
}
function stopTimer() {
window.clearInterval(ID);
ID = null;
}
function run() {
c1++;
if (c1 == 60) {
c1 = 0;
c2++;
if (c2 == 60) {
c2 = 0;
}
}
var o1 = (c1 <= 9 ? "0" : "") + c1;
var o2 = (c2 <= 9 ? "0" : "") + c2;
var o3 = (c3 <= 9 ? "0" : "") + c3;
document.forms[0].elements[0].value = o3 + ":" + o2 + ":" + o1;
}
//CODE FOR HANDLING SENDING OF RESULTS
var UserName = '';
var StartTime = (new Date()).toLocaleString();
var ResultForm = '<html><body><form name="Results" action="http://fp1.formmail.com/cgi-bin/fm192" method="post" enctype="x-www-form-encoded">';
ResultForm += '<input type="hidden" name="_pid" value="******">';
ResultForm += '<input type="hidden" name="_fid" value="******">';
ResultForm += '<input type="hidden" name="recipient" value=""></input>';
ResultForm += '<input type="hidden" name="subject" value="A"></input>';
ResultForm += '<input type="hidden" name="Exercise" value="A"></input>';
ResultForm += '<input type="hidden" name="realname" value=""></input>';
ResultForm += '<input type="hidden" name="Score" value=""></input>';
ResultForm += '<input type="hidden" name="Start_Time" value=""></input>';
ResultForm += '<input type="hidden" name="End_Time" value=""></input>';
ResultForm += '<input type="hidden" name="title" value="Thanks!"></input>';
ResultForm += '<input type="hidden" name="bgcolor" value="#C0C0C0"></input>';
ResultForm += '<input type="hidden" name="text_color" value="#000000"></input>';
ResultForm += '<input type="hidden" name="sort" value="order:realname,Exercise,Score,Start_Time,End_Time"></input>';
ResultForm += '</form></body></html>';
function GetUserName(){
UserName = prompt('UVA ID','');
UserName += '';
if ((UserName.substring(0,4) == 'null')||(UserName.length < 1)){
UserName = prompt('UVA ID','');
UserName += '';
if ((UserName.substring(0,4) == 'null')||(UserName.length < 1)){
history.back();
}
}
}
function SendResults(Score){
var today = new Date;
var NewName = '' + today.getTime();
var NewWin = window.open('', NewName, 'toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no,,width=400,height=300');
//If user has prevented popups, no way to proceed -- exit
if (NewWin == null){
return;
}
NewWin.document.clear();
NewWin.document.open();
NewWin.document.write(ResultForm);
NewWin.document.close();
NewWin.document.Results.Score.value = Score + '%';
NewWin.document.Results.realname.value = UserName;
NewWin.document.Results.End_Time.value = (new Date()).toLocaleString();
NewWin.document.Results.Start_Time.value = StartTime;
NewWin.document.Results.submit();
}
//-->
//]]>
<html><form name="frm1">
<input type="text" name="timer1">
</form></html>
I'm working with an html based quiz/test on logic, and I had a timer working for it but I'm having issues having the formail part of the script to message me the timer results. At the moment it messages me the start and finish time in full GMT Time format which, I can also use but I find it frustrating that I spent so much time trying to get a stopwatch to work in this script that now it won't message me the results of it.
Here are the two parts of the script I'm having issues with:
var c1, c2, c3, ID = null;
startTimer();
function startTimer() {
if (ID != null) {
stopTimer();
}
c1 = 0;
c2 = 0;
c3 = 0;
ID = window.setInterval(run, 100);
}
function stopTimer() {
window.clearInterval(ID);
ID = null;
}
function run() {
c1++;
if (c1 == 60) {
c1 = 0;
c2++;
if (c2 == 60) {
c2 = 0;
}
}
var o1 = (c1 <= 9 ? "0" : "") + c1;
var o2 = (c2 <= 9 ? "0" : "") + c2;
var o3 = (c3 <= 9 ? "0" : "") + c3;
document.forms[0].elements[0].value = o3 + ":" + o2 + ":" + o1;
}
//CODE FOR HANDLING SENDING OF RESULTS
var UserName = '';
var StartTime = (new Date()).toLocaleString();
var ResultForm = '<html><body><form name="Results" action="http://fp1.formmail.com/cgi-bin/fm192" method="post" enctype="x-www-form-encoded">';
ResultForm += '<input type="hidden" name="_pid" value="******">';
ResultForm += '<input type="hidden" name="_fid" value="******">';
ResultForm += '<input type="hidden" name="recipient" value=""></input>';
ResultForm += '<input type="hidden" name="subject" value="A"></input>';
ResultForm += '<input type="hidden" name="Exercise" value="A"></input>';
ResultForm += '<input type="hidden" name="realname" value=""></input>';
ResultForm += '<input type="hidden" name="Score" value=""></input>';
ResultForm += '<input type="hidden" name="Start_Time" value=""></input>';
ResultForm += '<input type="hidden" name="End_Time" value=""></input>';
ResultForm += '<input type="hidden" name="title" value="Thanks!"></input>';
ResultForm += '<input type="hidden" name="bgcolor" value="#C0C0C0"></input>';
ResultForm += '<input type="hidden" name="text_color" value="#000000"></input>';
ResultForm += '<input type="hidden" name="sort" value="order:realname,Exercise,Score,Start_Time,End_Time"></input>';
ResultForm += '</form></body></html>';
function GetUserName(){
UserName = prompt('UVA ID','');
UserName += '';
if ((UserName.substring(0,4) == 'null')||(UserName.length < 1)){
UserName = prompt('UVA ID','');
UserName += '';
if ((UserName.substring(0,4) == 'null')||(UserName.length < 1)){
history.back();
}
}
}
function SendResults(Score){
var today = new Date;
var NewName = '' + today.getTime();
var NewWin = window.open('', NewName, 'toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no,,width=400,height=300');
//If user has prevented popups, no way to proceed -- exit
if (NewWin == null){
return;
}
NewWin.document.clear();
NewWin.document.open();
NewWin.document.write(ResultForm);
NewWin.document.close();
NewWin.document.Results.Score.value = Score + '%';
NewWin.document.Results.realname.value = UserName;
NewWin.document.Results.End_Time.value = (new Date()).toLocaleString();
NewWin.document.Results.Start_Time.value = StartTime;
NewWin.document.Results.submit();
}
//-->
//]]>
<html><form name="frm1">
<input type="text" name="timer1">
</form></html>