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!

If you have any problems with the registration process or your account login, please contact us and we'll help you get started. We look forward to seeing you on the forums!

Already a member? Login to stop seeing this message.
  1. theZcuber

    theZcuber Premium Member

    2,077
    0
    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. theZcuber

    theZcuber Premium Member

    2,077
    0
    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
  3. Kirjava

    Kirjava Colourful

    6,130
    3
    Mar 26, 2006
    WCA:
    2006BARL01
    YouTube:
    snkenjoi
    After <div class="fw-paragraphbottom">.
     
  4. theZcuber

    theZcuber Premium Member

    2,077
    0
    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)
     
  5. theZcuber

    theZcuber Premium Member

    2,077
    0
    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
     
  6. Kirjava

    Kirjava Colourful

    6,130
    3
    Mar 26, 2006
    WCA:
    2006BARL01
    YouTube:
    snkenjoi
    Eh, I had it working fine before.

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

    theZcuber Premium Member

    2,077
    0
    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
     
  8. theZcuber

    theZcuber Premium Member

    2,077
    0
    May 8, 2011
    Central NY, US
    WCA:
    2012PRAT02
    Lol talk about broken code
     
  9. Kirjava

    Kirjava Colourful

    6,130
    3
    Mar 26, 2006
    WCA:
    2006BARL01
    YouTube:
    snkenjoi
    ****ing firefox, gimmie a sec
     
  10. Kirjava

    Kirjava Colourful

    6,130
    3
    Mar 26, 2006
    WCA:
    2006BARL01
    YouTube:
    snkenjoi
  11. theZcuber

    theZcuber Premium Member

    2,077
    0
    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)
     
  12. Kirjava

    Kirjava Colourful

    6,130
    3
    Mar 26, 2006
    WCA:
    2006BARL01
    YouTube:
    snkenjoi
    no idea. your code is quite the cluster****
     
  13. theZcuber

    theZcuber Premium Member

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

    That's just what the site puts up
     
  14. theZcuber

    theZcuber Premium Member

    2,077
    0
    May 8, 2011
    Central NY, US
    WCA:
    2012PRAT02
    Updated first post with a new problem :(
     
  15. joey

    joey Member

    4,407
    0
    Apr 8, 2007
    WCA:
    2007GOUL01
    YouTube:
    cardologist
    Code:
    var int;
    function start(){
    	int = setInterval('timer()',10);
    }
    function stop(){
    	clearInterval(int);
    }
    
     
  16. theZcuber

    theZcuber Premium Member

    2,077
    0
    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
     
  17. theZcuber

    theZcuber Premium Member

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

Share This Page