Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    this function stops my clock working

    I have a clock that works onbodyload, however using the below function on the same page, stops my clock even coming up, any help would be great.

    Code:
      <script language="JavaScript">
    var HAS_EXPIRED = 'Time has Expired!';
    var IS_NONE = 'None';
    function secondCountdown(s){
    	
    	if(s){
    		
    		var timeleft = document.getElementById('timeleft').innerHTML;
    		
    		if((timeleft == HAS_EXPIRED) || (timeleft == IS_NONE)) return false;
    		
    		timeleft = timeleft.replace('<font>', '');
    		timeleft = timeleft.replace('</font>', '');
    		
    		var time = timeleft.split(":");
    		
    		var secs = time[2] * 1;
    		var mins = time[1] * 1;
    		var hrs = time[0] * 1;
    		
    		secs += (mins * 60) + (hrs * 3600);
    		secs -= 1;
    		
    		if(secs <= 0){
    			
    			document.getElementById('timeleft').innerHTML = HAS_EXPIRED;
    			return false;
    			
    		} else {
    			
    			hrs = Math.floor(secs/3600);
    			secs -= (hrs * 3600);
    			
    			mins = Math.floor(secs/60);
    			secs -= (mins * 60);			
    							
    			if(hrs < 10)	hrs = '0' + hrs;
    			if(mins < 10)	mins = '0' + mins;			
    			if(secs < 10)	secs = '0' + secs;
    					
    			document.getElementById('timeleft').innerHTML = hrs + ':' + mins + ':' + secs;
    			
    		}
    		
    	}
    	
    	setTimeout('secondCountdown(true)',1000);
    	
    }
    
    bootloaderAdd('secondCountdown()');
    bootloaderOn();
    
    </script>
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,925
    Thanks
    56
    Thanked 549 Times in 546 Posts
    almost certainly you have (at least) two variables with the same name, but it is hard to tell really without seeing the clock function, too

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry, i should have posted it,

    Code:
    function updateClock ( )
    {
    
     updateClock.tag=updateClock.tag|| document.getElementById("clock");
     var m=" AM",
      str=(new Date).toGMTString().match(/(\d{2}\:)+\d{2}/g)[0].replace(/^\d+/, function(a,b){
        a*=1;
        if(a>12){ a= (a-12)||12; m=" PM";}
         return ("00"+a).slice(-2);
      }) + m;
    
      if(updateClock.last!=str){
        updateClock.last=str;
        updateClock.tag.firstChild.nodeValue = str;
      }
    }
    also below is my body onload, please tell me if it is missing something:

    Code:
    <body onLoad="updateClock(); setInterval('updateClock()', 300 ); secondCountdown(s); ">
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #4
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    remove these 2 lines from your code -

    Code:
    bootloaderAdd('secondCountdown()');
    bootloaderOn();
    leave everything else as it is
    <DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
    <DmncAtrny> And then hurl it through the window of a Sony officer
    <DmncAtrny> and run like hell

    Portfolio, Tutorials - http://www.nomanic.biz/

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    that did bring back the clock, however it stopped the coundown, here is the bootloader that you told me to remove:

    Code:
    function bootloaderOn(){
      window.onload = bootloaderGo;
    }
    function bootloaderGo(){
      for(var i = 0;i < bootloaders.length;i++)
        eval(bootloaders[i]);
    }
    function bootloaderAdd(func){
      bootloaders[bootloaders.length] = func;
    }
    var bootloaders = new Array();
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #6
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    should be this -

    Code:
    <body onLoad="updateClock(); setInterval('updateClock()', 300 ); secondCountdown(); ">
    the 's' was crashing it
    <DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
    <DmncAtrny> And then hurl it through the window of a Sony officer
    <DmncAtrny> and run like hell

    Portfolio, Tutorials - http://www.nomanic.biz/

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    if i leave out the
    Code:
    bootloaderAdd('secondCountdown()');
    bootloaderOn();
    the clock works, however if i put it back in the clock stops working and the countdown works again :S
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #8
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    did you change your body onload line?
    <DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
    <DmncAtrny> And then hurl it through the window of a Sony officer
    <DmncAtrny> and run like hell

    Portfolio, Tutorials - http://www.nomanic.biz/

  • #9
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    yes i did
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #10
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    can anybody else figure this one out as im still having trouble :S
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #11
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,925
    Thanks
    56
    Thanked 549 Times in 546 Posts
    can you post your full code, and be a little more specific about what the problem is?

  • #12
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    basically, when this script is inserted into the page, the clock on my website stops working, this is the inserted page called countDown.js:

    Code:
    var HAS_EXPIRED = 'Time has Expired!';
    var IS_NONE = 'None';
    function secondCountdown(s){
    	
    	if(s){
    		
    		var timeleft = document.getElementById('timeleft').innerHTML;
    		
    		if((timeleft == HAS_EXPIRED) || (timeleft == IS_NONE)) return false;
    		
    		timeleft = timeleft.replace('<font>', '');
    		timeleft = timeleft.replace('</font>', '');
    		
    		var time = timeleft.split(":");
    		
    		var secs = time[2] * 1;
    		var mins = time[1] * 1;
    		var hrs = time[0] * 1;
    		
    		secs += (mins * 60) + (hrs * 3600);
    		secs -= 1;
    		
    		if(secs <= 0){
    			
    			document.getElementById('timeleft').innerHTML = HAS_EXPIRED;
    			return false;
    			
    		} else {
    			
    			hrs = Math.floor(secs/3600);
    			secs -= (hrs * 3600);
    			
    			mins = Math.floor(secs/60);
    			secs -= (mins * 60);			
    							
    			if(hrs < 10)	hrs = '0' + hrs;
    			if(mins < 10)	mins = '0' + mins;			
    			if(secs < 10)	secs = '0' + secs;
    					
    			document.getElementById('timeleft').innerHTML = hrs + ':' + mins + ':' + secs;
    			
    		}
    		
    	}
    	
    	setTimeout('secondCountdown(true)',1000);
    	
    }
    
    bootloaderAdd('secondCountdown()');
    bootloaderOn();
    then theres the bootloaderadd function from the bottom of that one which is this:

    Code:
    function bootloaderOn(){
      window.onload = bootloaderGo;
    }
    function bootloaderGo(){
      for(var i = 0;i < bootloaders.length;i++)
        eval(bootloaders[i]);
    }
    function bootloaderAdd(func){
      bootloaders[bootloaders.length] = func;
    }
    var bootloaders = new Array();
    then on the actual page theres this peice of code:

    PHP Code:

    <div id="timeleft"><?php echo "".maketime2($fetch2->banktime).""?></div>
    now with the countDown.js page included on the page the JS clock stops working, if you would like the code for the clock let me know and ill post it for you?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #13
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,925
    Thanks
    56
    Thanked 549 Times in 546 Posts
    just give us the whole shebang, html and all... or even a link if the page is live...

  • #14
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    the page is live, but you would need to log in, i can supply a password for you and username if that would be easier?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #15
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,925
    Thanks
    56
    Thanked 549 Times in 546 Posts
    ok - or why don't you set up a guest account so we can all log in?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •