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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS to show the timer in html under title instead of in the status bar

Status
Not open for further replies.

jomat

Programmer
Dec 21, 2023
1
0
0
US
I have a really old js (15 years old) that I used to use. The script is for a quiz. The htm calls the js and the quiz begins. The timer used to be displayed in the browser status bar. Since many many years ago, the status bar is no longer available in edge or chrome anymore.
Can some help with some suggestion on getting the timer to show on an htm instead of the status bar?
Thanks ahead of time.

...code begins:

function Question (qname,
type,
qstring,
response,
comment,
corrects,
explan,
score,
ifcorrect,ifwrong,ifnull,
img)
{this.qname=qname;
this.type=type;
this.qstring=qstring;
this.response=response;
this.comment=comment;
this.corrects=corrects;
this.explan=explan;
this.score=score;
this.ifcorrect=ifcorrect;
this.ifwrong=ifwrong;
this.ifnull=ifnull;
this.img=img;
}

var zin=1,top=0, mycount=0, waitTime=3600, qright=0, mycomment;
var global=new Array(3);
var recent, recent2, recdone=false, opera7, opera=CheckOpera56();
P7_OpResizeFix();
function P7_OpResizeFix(a) { //v1.1 by PVII
if(!window.opera){return;}if(!document.p7oprX){
document.p7oprY=window.innerWidth;document.p7oprX=window.innerHeight;
document.onmousemove=P7_OpResizeFix;
}else{if(document.p7oprX){
var k=document.p7oprX-window.innerHeight;
var j=document.p7oprY - window.innerWidth;
if(k>1 || j>1 || k<-1 || j<-1){
document.p7oprY=window.innerWidth;document.p7oprX=window.innerHeight;
do_reposition();}}}
}
function cachewrite(s,idx){global[idx]+=s;}
function CheckOpera56()
{
var version;
if (navigator.userAgent.toLowerCase().indexOf('opera') == -1) return false;
version=parseInt(navigator.appVersion.toLowerCase());
if (version>6) {opera7=true; return false;}
if (version<5) return false;
return true;
}
resp=new Array("52","44","42","42")
corr=new Array("1","0","0","0")
comm=""
valu=""
quest001 = new Question(
"Question 1",
0,
"What is: <br>42 + 10 = ________",
resp,
comm,
corr,
"<small>52</small>",
valu,
1,
0,
0,
"");

resp=new Array("101","91","78","121")
corr=new Array("1","0","0","0")
comm=""
valu=""
quest002 = new Question(
"Question 2",
0,
"What is: <br>70 + 31 = __________",
resp,
comm,
corr,
"<small>101</small>",
valu,
1,
0,
0,
"");

resp=new Array("60","52","58","61")
corr=new Array("1","0","0","0")
comm=""
valu=""
quest003 = new Question(
"Question 3",
0,
"What is: <br>39 + 21 = _________",
resp,
comm,
corr,
"<small>60</small>",
valu,
1,
0,
0,
"");

resp=new Array("78","77","76","79")
corr=new Array("1","0","0","0")
comm=""
valu=""
quest004 = new Question(
"Question 4",
0,
"What is: <br>44 + 34 = _________",
resp,
comm,
corr,
"<small>78</small>",
valu,
1,
0,
0,
"");

resp=new Array("69","68","79","59")
corr=new Array("1","0","0","0")
comm=""
valu=""
quest005 = new Question(
"Question 5",
0,
"What is: <br>37 + 32 = ________",
resp,
comm,
corr,
"<small>69</small>",
valu,
1,
0,
0,
"");

questions = new Array (
quest001,quest002,quest003,quest004,quest005)

function doQuestion(quest)
{
var numdo;
var numord=eval(quest+1);
var i=-1, ii, type, myname, gadget;
type=questions[quest].type;
numdo=type>=3?1:questions[quest].response.length;
if (type<3) {
respcopy=new Array(numdo);corrcopy=new Array(numdo);
for (i=0; i<numdo; i++) respcopy=questions[quest].response;
respcopy.sort(myrandom);
for (i=0; i<numdo; i++) {
for (ii=0; ii<numdo; ii++) {
if (respcopy==questions[quest].response[ii]) {
corrcopy=questions[quest].corrects[ii];break;}}}
questions[quest].response=respcopy;
questions[quest].corrects=corrcopy;}
if (opera && top==0) top=document.getElementById("wq_user").style.top;document.write("\n")
document.write(" <div id=\"q")
document.write(numord)
document.write("\" ")
document.write(opera?" style=\"position: absolute; visibility:hidden; top:"+top+"; z-index:"+(++zin)+";\"":" style=\"display:none\"");
document.write(">\n")
document.write(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n")
document.write(" <tr>\n")
document.write(" <td>\n")
document.write(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n")
document.write(" <tr height=25>\n")
document.write(" <td colSpan=5></td>\n")
document.write(" </tr>\n")
document.write(" <tr>\n")
document.write(" <td width=\"5%\" rowspan=\"3\"></td>\n")
document.write(" <td width=\"9%\" rowspan=\"3\" valign=\"top\" align=\"center\"><font face=\"Verdana\" size=\"7\" color=\"#C0C0C0\">")
document.write(numord)
document.write("</font></td>\n")
document.write(" <td width=\"1%\" rowspan=\"3\" background=\"m_vline.gif\">&nbsp;</td>\n")
document.write(" <td width=\"80%\" class=\"question\" valign=\"top\">\n")
document.write(" ")
if (questions[quest].img!="") {
document.write("\n")
document.write(" <img border=\"0\" hspace=\"10\" vspace=\"0\" align=\"left\" src=\"")
document.write(questions[quest].img)
document.write("\">\n")
document.write(" ")
}
document.write("\n")
document.write(" ")
document.writeln(questions[quest].qstring)
document.write("\n")
document.write(" </td>\n")
document.write(" <td width=\"5%\"></td>\n")
document.write(" </tr>\n")
document.write(" <tr height=10>\n")
document.write(" <td width=\"80%\"></td>\n")
document.write(" <td width=\"5%\"></td>\n")
document.write(" </tr>\n")
document.write(" <tr>\n")
document.write(" <td width=\"80%\" class=\"answer\">\n")
document.write(" ")
for (i=0; i<numdo; i++) {
myname=questions[quest].qname;
gadget="radio";
if (type>=3) gadget="text";
else if (type==1) {
myname+="_"+(i<9?"0":"")+(i+1);
gadget="checkbox";}
document.write("\n")
document.write(" ")
document.write(type==7?"<textarea name=\""+myname+"\" rows=5 cols=30 class=\"input\">":" <input type="+gadget+" name=\""+myname);
if (type<3) document.write("\" value=\""+i+"\">\n")
else document.write(type==7?"</textarea>":"\" class=\"input\" value=\"\">\n")
if (type<3) document.write(questions[quest].response);
document.write("<br>\n")
document.write(" ")
}
document.write("\n")
document.write(" </td>\n")
document.write(" <td width=\"5%\"></td>\n")
document.write(" </tr>\n")
document.write(" <tr height=5>\n")
document.write(" <td colSpan=5></td>\n")
document.write(" </tr>\n")
document.write(" </table>\n")
document.write(" </td>\n")
document.write(" </tr>\n")
document.write(" <tr height=10>\n")
document.write(" <td>&nbsp;</td>\n")
document.write(" </tr>\n")
document.write(" </table>\n")
document.write(" </div>\n")
document.write(" <div id=\"q")
document.write(numord)
document.write("a\" ")
document.write(opera?" style=\"position: absolute; visibility:hidden; top:"+top+"; z-index:"+(++zin)+";\"":" style=\"display:none\"");
document.write(">\n")
document.write(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n")
document.write(" <tr>\n")
document.write(" <td width=\"14%\"></td>\n")
document.write(" <td width=\"86%\"> \n")
document.write(" ")
document.write("\n")
document.write(" ")
if (quest<questions.length) {
document.write("\n")
document.write(" <a href=\"javascript:void(0)\" ")
document.write(" onClick=\"myshow("+quest+",2)\"")
document.write(" onmouseout=\"flipImage ('Next")
document.write(numord)
document.write("', 'NextImage_normal');\" onmouseover=\"flipImage ('Next")
document.write(numord)
document.write("', 'NextImage_up');\"><img alt=\"Next\" border=0 height=20 width=100 name=Next")
document.write(numord)
document.write(" src=\"m_next_button.gif\"></a>\n")
document.write(" ")
}
document.write("\n")
document.write(" ")
document.write("\n")
document.write(" </td>\n")
document.write(" </tr>\n")
document.write(" <tr height=5>\n")
document.write(" <td colSpan=\"2\"></td>\n")
document.write(" </tr>\n")
document.write(" </table>\n")
document.write(" </div>\n")
document.write(" ")
}
function doTest() {
var count, i;
questions.sort(myrandom);
for (i=0; i<questions.length; i++) {
questions.qname="Question "+(i+1);}
count=questions.length;
for (i=0; i<count; i++) doQuestion(i);
}
function fill(s,l){
s=s+""
for (y=1;y<=l;y++)
if (s.length>=l) break; else s="0"+s;
return s
}
function CheckQName(wapf,ii,i,multi,selection){
var len;
if (!multi) return(wapf.elements[ii].name==questions.qname);
len=questions.qname.length;
if (wapf.elements[ii].name.substring(0,len)!=questions.qname) return false;
if (wapf.elements[ii].name.substring(len,len+1)!="_") return false;
if (eval(wapf.elements[ii].name.substring(len+1,len+3))==(selection+1)) return true;
return false;
}
function errore(uno,due,tre)
{
if (!errori) global[1]="<H3>You have made the following errors</H3>";
++errori;
cachewrite("<p><b>"+uno+"</b><br>"+due+"<br>"+mycomment+tre+"</p>",2);
mycomment="";
}
function correct(wapf)
{
var i, ii, t, re, tmp, selection, multi, multipage=1, type, isnull, iswrong, iscorrect, evaluation=0, total=0, udat;
errori=waitTime=0;
udat=new Array();
for (i=0, ii=0; i<wapf.elements.length; i++)
{tmp=wapf.elements;
if (tmp.name.substring(0,13)=="Quiz.UserData"){
t=tmp.name.substring(14,tmp.name.length);
re=new RegExp("_", "g");
t=t.replace(re," ");
udat[ii++]=t+": <i>"+tmp.value+"</i><br>";
if (opera) tmp.value="";}}
global[0]=global[2]="";
global[1]="<h3>Congratulations, you haven't made any errors</h3>";
cachewrite("<html><head><title>Results</title><BASE target='_blank'></head><body bgcolor='#FFFFFF'><font face='Verdana, Arial'><table border=0 cellpadding=0 cellspacing=0 width='100%' bgcolor='#C0C0C0'><tr><td width='100%'><font face='Verdana, Arial' size=5 color='#FFFFFF'><b>&nbsp;Results</b></font></td></tr></table>",0)
now= new Date()
cachewrite("<small><p>"+fill((now.getMonth()+1),2)+"/"+fill(now.getDate(),2)+"/"+now.getYear()+"&nbsp;&nbsp;"+fill(now.getHours(),2)+":"+fill(now.getMinutes(),2)+"</p>",0)
cachewrite("<b>Math Test</b><br><br>\n",0);
if (udat.length>0) {
cachewrite("<b>Information</b><br>\n",0);
for (i=0; i<udat.length; i++) cachewrite(udat,0);}
if (opera7 && multipage) {
for (i=0; i<questions.length; i++) {
id=document.getElementById("q"+(i+1));
id2=document.getElementById("q"+(i+1)+"a");
id.style.display=id2.style.display="block";}
document.getElementById('wq_final').style.display='block';
}

for (i=0; i<questions.length; i++) {
if (opera && multipage) {
id=document.getElementById("q"+(i+1));
id2=document.getElementById("q"+(i+1)+"a");
id.style.visibility=id2.style.visibility="visible";}
type=questions.type;
if (type==1) multi=1;
else multi=0;
isnull=true;
iscorrect=false;iswrong=false;
selection=0;
evaluation=0;
mycomment="";
for (ii=0; ii<wapf.elements.length; ii++) {
if (CheckQName(wapf,ii,i,multi,selection)) {
if (type>=3 && wapf.elements[ii].value!="") {
isnull=false;
if (wapf.elements[ii].value.toLowerCase()==questions.corrects.toLowerCase()) iscorrect=true;
else iswrong=true;
++selection;}
else if (wapf.elements[ii].checked) {
if (questions.score!="") evaluation+=questions.score[selection];
if (isnull) isnull=false;
if (questions.corrects[selection]=="1") iscorrect=(iswrong==false)?true:false;
else {
iswrong=true;
if (multi && questions.corrects!='') errore(questions.qname,"The checkbox <i>"+questions.response[selection]+"</i> shouldn't have been selected.",questions.explan)
}
if (questions.comment!="" && questions.comment[selection]!="")
mycomment+=((iscorrect || questions.corrects=='')?"<b>"+questions.qname+"</b><br>":"")+"<small>"+questions.comment[selection]+"</small><br>";
} else {
if (questions.corrects[selection]=="1") {
iswrong=true;
if (multi && questions.corrects!='') errore(questions.qname,"The checkbox <i>"+questions.response[selection]+"</i> should have been selected.",questions.explan);
}}
++selection;
}}
if (multi==false && (isnull || iswrong)) {
var okresp="", z;
if (type>=3) okresp=questions.corrects;
else {
for (z=0; z<questions.corrects.length; z++) {
if (questions.corrects[z]==1) {
okresp=questions.response[z];
break;
}}}
if (okresp!="") errore(questions.qname,"The right answer was <i>"+okresp+".</i>",questions.explan);
}
if (mycomment!="") cachewrite(mycomment,2);
if (questions.corrects!="") ++qright;
if (isnull) evaluation+=questions.ifnull;
else if (iswrong) evaluation+=questions.ifwrong;
else if (iscorrect) evaluation+=questions.ifcorrect;
total+=evaluation;}
if (qright==0) global[1]="<br>";
if (errori) cachewrite("<br><b>You have made "+errori+" "+(errori==1?"error":"errors")+".</b>",2);
cachewrite("<br><b>Total score: "+total+".</b><br>",2);

cachewrite("</small><hr noshade><center><form>",2)
printest="print()";
cachewrite("<input type='button' value='Print...' onClick='"+printest+"'>&nbsp;&nbsp;&nbsp;&nbsp;",2)
cachewrite("<input type='button' value='Back' onClick='history.back()'></form></center>",2)
cachewrite(aknw,2)
winr=window
for (i=0; i<3; i++) winr.document.write(global);winr.document.close()
if ((opera || opera7) && multipage) {
document.forms[0].elements[0].value='Print...';
document.forms[0].elements[1].value='Back';
for (i=0; i<questions.length; i++) {
id=document.getElementById("q"+(i+1));
id2=document.getElementById("q"+(i+1)+"a");
opera?id.style.visibility=id2.style.visibility="hidden":id.style.display=id2.style.display="none";}}
}
aknw="<br><p align='center'><small><small>Created and managed with <a title='Click here to visit nonprofit site' href=' target = '_blank'>My School</a></small></small></p>"
function myrandom(a,b)
{
var rc;
do {rc=Math.floor(Math.random()*3)-1;} while (rc==2);
return(rc);
}
function update_time(t) {
self.status=t;}
function stms(s){
if (Math.abs(tmMx)>=3600){
h=Math.floor(s/3600);m=Math.floor((s%3600)/60);s=((s%3600)%60);return fill(h,2)+':'+fill(m,2)+':'+fill(s,2);
}else{m=Math.floor(s/60);s=s%60;return fill(m,2)+':'+fill(s,2);}}
function shtm(t){
tmVl=t+1;update_time(stms(Math.abs(t)))
if (waitTime==0) return;
tmId = setTimeout('shtm(tmVl)',1000)
if (t==((tmMx>0)? tmMx : 0)){
clearTimeout(tmId)
alert('Time is over, correcting questionnaire now.')
if (mycount<questions.length) for (i=mycount; i<=questions.length; i++) myshow(i,0);
correct(document.WapForm)}}
function checkTime(){
tmMx=-waitTime;
if (tmMx!=0){
alert('Time to complete your questionnaire is: '+stms(Math.abs(tmMx))+'\n\nPlease check time count.');
shtm((tmMx>0) ? 0 : tmMx)}}
function checkBrowser()
{
var browser=new Array('microsoft internet explorer','netscape','opera');
var version=new Array(5,5,6);
for (i=0; i<3; i++) {
var ref, pos=navigator.appVersion.lastIndexOf('MSIE ');
if (pos == -1) ref=parseInt(navigator.appVersion);
else {pos+=5;ref=eval(navigator.appVersion.charAt(pos));}
if (navigator.appName.toLowerCase()==browser && ref>=version)
break;}
if (i==3) {
alert('The browser'+navigator.appName+' '+navigator.appVersion+' is not supported');
return false;}
return true;}
function myshow(count,dif)
{
var id, id2, wq_user, id_str, id2_str;
if (recdone==false && checkBrowser()==false) return;
if (recdone==false && waitTime!=0) checkTime();
if (dif!=-1) count+=dif;
mycount=count;
if (count==questions.length+1) {id_str="wq_final";id2_str="wq_final2"}
else {id_str="q"+count;id2_str="q"+count+"a";}
if (document.getElementById){
id=document.getElementById(id_str);
id2=document.getElementById(id2_str);
wq_user=document.getElementById("wq_user");
if (count==questions.length+1 && opera) {id2.style.top=id.style.top+id.style.height;}
} else if (document.all) {
id=document.all[id_str];
id2=document.all[id2_str];
wq_user=document.all["wq_user"];
} else {
id=eval(id_str);
id2=eval(id2_str);
wq_user=eval("wq_user");}
if (recdone==false) {
recent=wq_user;
recent2="";
recdone=true;}
opera?recent.style.visibility="hidden":recent.style.display="none";
if (recent2!="") opera?recent2.style.visibility="hidden":recent2.style.display="none";
opera?id.style.visibility="visible":id.style.display="block";
opera?id2.style.visibility="visible":id2.style.display="block";
if (count<questions.length+1 && questions[count-1].type>2) document.WapForm.elements[questions[count-1].qname].focus();
recent=id;recent2=id2;}
function do_reposition(){
var id, id2, wq_user, wq_final, wq_footer, i, y, h, max=0;
wq_user=document.getElementById("wq_user");
if (mycount>0) wq_user.style.visibility="hidden";
for (i=1; i<=questions.length; i++) {
id=document.getElementById("q"+i);
id2=document.getElementById("q"+i+"a");
id2.style.top=id.style.top+id.style.height;
h=id2.style.height;y=id2.style.top;
if (mycount==i) id.style.visibility=id2.style.visibility="visible";
if (y+h>max) max=y+h;}
wq_final=document.getElementById("wq_final");
wq_footer=document.getElementById("wq_footer");
if (wq_final.style.visibility!="hidden") {
wq_final.style.top=max;max+=wq_final.style.height;}
if (wq_footer.style.visibility!="hidden") {
wq_footer.style.top=max;}
}

...code ends.
 
please, post your properly formatted code between the tags:
[pre]
Code:
[/pre]
[pre]...[/pre]
[pre]
[/pre]
 
You could try something like this but replace the time with your countdown timer
Code:
<html>
    <head>
        <meta http-equiv="refresh" content="1">
        <title></title>
    </head>
    <body>
        <script>
const now = new Date()
const nowdt = now.toLocaleString()
document.title = nowdt
        </script>
    </body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top