ramli66 Posted March 20, 2007 Share Posted March 20, 2007 Hello all, I want to create a texbox where time is counted up starting from 00:00:00this however can not be initiated by a onload element directly in the body.Can anybody direct me to somwhere were i can find a snipplet of this. Becouse i cant seem t find it on fora or internet.Thx in advance,ramli66 Link to comment Share on other sites More sharing options...
aspnetguy Posted March 20, 2007 Share Posted March 20, 2007 <html><head> <title></title></head><body> <input type="text" id="counter" value="00:00:00.0"/> <script type="text/javascript"> var count = document.getElementById("counter"); var milli = 0; var sec = 0; var min = 0; var hr = 0; setInterval(counter,100); function counter() { milli++; if(milli == 10) { milli = 0; sec++; } if(sec == 60) { sec = 0; min++; } if(min == 60) { min = 0; hr++; } var str_milli = milli; var str_sec = sec; if(sec < 10) str_sec = "0" + str_sec; var str_min = min; if(min < 10) str_min = "0" + str_min; var str_hr = hr; if(hr < 10) str_hr = "0" + str_hr; //show milli //count.value = str_hr + ":" + str_min + ":" + str_sec + "." + str_milli; //don't show milli count.value = str_hr + ":" + str_min + ":" + str_sec; } </script></body></html> Link to comment Share on other sites More sharing options...
ramli66 Posted March 20, 2007 Author Share Posted March 20, 2007 Thx that works :) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now