Wednesday, 15 February 2012

stopwatch clear variable javascript -



stopwatch clear variable javascript -

hey i'm extremely unfamiliar in using javascript... need help clearing time (this should stop time clear it) in script. see: function clear() :) if have suggestions in merging stop\start button 1 function that'd appreciated too. give thanks again!

<script type='text/javascript'> var clsstopwatch = function () { var startat = 0; var laptime = 0; var = function () { homecoming (new date()).gettime(); }; this.start = function () { startat = startat ? startat : now(); }; this.stop = function () { laptime = startat ? laptime + now() - startat : laptime; startat = 0; }; this.time = function () { homecoming laptime + (startat ? now() - startat : 0); }; }; var x = new clsstopwatch(); var $time; var clocktimer; function pad(num, size) { var s = "0000" + num; homecoming s.substr(s.length - size); } function formattime(time) { var h = m = s = ms = 0; var newtime = ''; m = math.floor(time / (60 * 1000)); time = time % (60 * 1000); s = math.floor(time / 1000); ms = time % 1000; newtime = pad(m, 2) + ':' + pad(s, 2) + ':' + pad(ms, 2); homecoming newtime; } function show() { $time = document.getelementbyid('time'); update(); } function update() { $time.innerhtml = formattime(x.time()); } function start() { clocktimer = setinterval("update()", 1); x.start(); } function stop() { x.stop(); document.getelementbyid('counter').value = formattime(x.time()); clearinterval(clocktimer); } function clear() { x.stop(); ????????? function need help on } </script>

html:

<body onload="show();"> <form action="submit.php" method="post"/> time: <span id="time"></span><br/> <!--<input type="text" name-"time">--> <input type="button" value="start" onclick="start();"> <input type="button" value="stop" onclick="stop();"> <input type="button" value="clear" onclick="clear();"> <input type="submit" value="save" onclick="stop();"> <br/><br/>

you, forgot set show() in start() function

here working fiddle http://jsfiddle.net/64gfm/

change clear() function clearwatch() clear inbult function new updated js fiddle http://jsfiddle.net/64gfm/1/

function clearwatch() { x.stop(); x.clear(); clearinterval(clocktimer); update(); }

hope, may help you. have anice day. :)

javascript

No comments:

Post a Comment