# Need Help With Coding

Discussion in 'Off-Topic Discussion' started by theZcuber, Aug 24, 2011.

Welcome to the Speedsolving.com. You are currently viewing our boards as a guest which gives you limited access to join discussions and access our other features. By joining our free community of over 30,000 people, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Alright, I'm back again, and need some more help. This time I'm trying to code a very simple timer, not even a cubing timer (although I might make it one). I can't seem to get the timer to stop at all.

Source code:
Code:
<script type='text/javascript'>
function start(){
window.int = setInterval('timer()',10);
document.getElementById('startstop').onkeydown = 'stop()';
document.getElementById('startstop').value = 'STOP';
}
function stop(){
int = clearInterval(int);
document.getElementById('startstop').onkeydown = 'start()';
document.getElementById('startstop').value = 'START';
var t = document.getElementById('times').innerHTML;
var ct = document.getElementById('sec').innerHTML + document.getElementById('frac').innerHTML;
document.getElementById('times').innerHTML = t + ' ,' + ct;
}
function timer(){
// Define variables
var frac = Math.round(document.getElementById('frac').innerHTML);
var sec = Math.round(document.getElementById('sec').innerHTML);

// Change decimal and second
frac = frac + 1;
if(frac <= 9){
frac = '0' + frac;
}
else if(frac == 100){
frac = '00';
sec = sec + 1;
}

// Change time displayed
document.getElementById('frac').innerHTML = frac;
document.getElementById('sec').innerHTML = sec;
}
</script>

<table width='1000' height='450'><tr>
<td valign='middle' align='center'>

<font size='7'><span id='time' onkeyup='start()'><span id='sec'>0</span>.<span id='frac'>00</span></span></font>
<br/>
<input type='text' value='START' onkeydown='start()' maxlength='0' size='12' id='startstop'/>
<br/><br/>
<span id='times'></span>
</td>
</tr></table>

As you can see, under stop(), I put the clear.interval. I've tried putting in window.clear.interval and/or window.int = ... but none have worked. I was just wondering how I should go about getting it to stop in Firefox. This is actually for a project, and I need a timer to show in the corner, but don't want something larger like qqTimer.

Last edited: Dec 6, 2011
2. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Could you show me where I would need to insert the </div>? It might be in a sidebar module I took from PayPal's code...

EDIT: I see where you mean to insert it. Just at the end of the second view cart button, correct?

Last edited: Aug 24, 2011
4. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi
After <div class="fw-paragraphbottom">.

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Hmm...weird

Now to try and figure out how to get that inserted (and how a </div> got removed)

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Just did a non-live version of the webpage by inserting it (anywhere from 1-3 </div>s) and all it did was add in the background colour for the sidebar, but nothing else

7. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi
Eh, I had it working fine before.

I'll send you a fixed copy when I get home.

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Alright. After I receive the fixed copy (and hopefully how to insert it with webs) I'll send you the \$5

9. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi

May 8, 2011
Central NY, US
WCA:
2012PRAT02

11. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi
****ing firefox, gimmie a sec

12. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi

May 8, 2011
Central NY, US
WCA:
2012PRAT02
So now the question remains...was this my coding fault or was it the site I'm using?

(and how to insert the </div> tags without replacing everything)

14. ### KirjavaColourful

6,123
17
Mar 26, 2006
WCA:
2006BARL01
snkenjoi
no idea. your code is quite the cluster****

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Yeah it's no where near like that when I'm editing it Anything I code is nice and organized

That's just what the site puts up

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Updated first post with a new problem

17. ### joeyMember

Apr 8, 2007
WCA:
2007GOUL01
cardologist
Code:
var int;
function start(){
int = setInterval('timer()',10);
}
function stop(){
clearInterval(int);
}


May 8, 2011
Central NY, US
WCA:
2012PRAT02
Although I did set var int outside a function, it still doesn't work

In case you want a live version of this timer, please go here

May 8, 2011
Central NY, US
WCA:
2012PRAT02
Can anybody help me with this?