JavaScript - Stopwatch
hi everyone, I am currently working on a stopwatch and I can't for the life of me get it inside this textbox.. Can anyone help with it? no matter what I seem to try it always goes outside of it...
Code: <html> <head> <title> stopwatch </title> <script type="text/javascript"> var setT, h, m, s; function startWatch(b){ var ticker=document.getElementById('ticker'); var HH=h<10?'0'+h:h; var MM=m<10?'0'+m:m; var SS=s<10?'0'+s:s; ticker.innerHTML = HH+':'+MM+':'+SS; if(!b){stopWatch();return} s++; if(s==60){s=0;m++} if(m==60){m=0;h++} setT=setTimeout(function(){startWatch(b)},50) } function stopWatch(){ clearTimeout(setT); } function resetWatch(){ h=0; m=0; s=0; startWatch(false) } onload=resetWatch </script> </head> <body> <form action=""> <input type="button" value="start clock" onclick="startWatch(true)"> <input type="button" value="stop clock" onclick="stopWatch()"> <input type="button" value="reset clock" onclick="resetWatch()"> <br> <br> <span id="ticker"></span> <BR> <INPUT type="text" id="ticker"> </form> </body> </html> Similar TutorialsI've been working on a stopwatch script and being fairly familiar with Javascript I've coded the following... function y() { setTimeout("x()",1000) } function x() { var a=0; var b=0; var c=0; var d=0; for(i=0;i=1;i=i+0); { txtbox1.value=a + b + ":" + c + d; d++; if (d==10); { d=0; c++; } if (c==6); { d=0; c=0; b++; } if (b==10); { d=0; c=0; b=0; a++; } } } </script> <input type="textbox" name="txtbox1"> <input type="button" name="b1" value="Start timer" onclick="y()"> Hi there. I am wanting to create a countdown timer that is based on a SELECT feature. If a user selected 15 MINUTES, the script would know 15 minutes was selected and would prompt start to time down when selected. Or if the user selected 30 MINUTES it would go to countdown from 30 minutes. I would also like a stopwatch feature on there if STOPWATCH was selected. It would also be great if when counting down the background box of the timer turns red to visually show the timer had gone over and start counting back up in minus to show how many minutes/seconds it has gone over. I've looked on good old Google but can't find a code i'm looking for! Thanks Ash hi, im new, so hey, great forum. I'm hoping someone can help - Im looking for a js stopwatch that would express a figure input by the end user - so for example the code could ask 'how many calories do you burn an hour' - user inputs 100 They start the stop watch and the stop watch show both the seconds/minutes increasing, but also show the calories increasing as (input="100"/60)/60 can anyone point in the right direction? many thanks Hi guys! I have a simple JavaScript stopwatch that displays the time using an html form with start/reset and clear buttons. Basically I'm making a speed calculator that converts seconds into MPH. All I need it to do is divide whatever the amount of seconds are by 40.91. So instead of it displaying the seconds being counted up (i.e. 2 seconds, would displayed as 20.455 MPH). Does that make sense? JavaScript is not my strong suit, and It's got me stumped. JavaScript: Code: var t=[0, 0, 0, 0, 0, 0, 0, 1]; function ss() { t[t[2]]=(new Date()).valueOf(); t[2]=1-t[2]; if (0==t[2]) { clearInterval(t[4]); t[3]+=t[1]-t[0]; t[4]=t[1]=t[0]=0; disp(); } else { t[4]=setInterval(disp, 43); } } function r() { if (t[2]) ss(); t[4]=t[3]=t[2]=t[1]=t[0]=0; disp(); t[7]=1; } function disp() { if (t[2]) t[1]=(new Date()).valueOf(); t[6].value=format(t[3]+t[1]-t[0]); } function format(ms) { var d=new Date(ms+t[5]).toString() .replace(/.*([0-9][0-9]:[0-9][0-9]:[0-9][0-9]).*/, '$1'); var x=String(ms%1000); while (x.length<3) x='0'+x; d+='.'+x; return d; } function load() { t[5]=new Date(1970, 1, 1, 0, 0, 0, 0).valueOf(); t[6]=document.getElementById('disp'); disp(); } HTML form: Code: <input type='text' id='disp' maxlength=12 readonly /> <button type='button' onclick='ss()' id='butt' data-inline="true">Start/Stop</button> <button type='button' onclick='r()' id='butt2' data-inline="true">Reset</button> Any help is greatly appreciated!!! |