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.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    firefox math messing up somehow?

    Code:
    <script type="text/javascript">
    function countItDown(){
    	var current=parseFloat(document.getElementById("currentsecondscount").value);
    	var seconds=current;
    	document.getElementById("debug").innerHTML="S "+current;
    	var minutes=Math.floor(seconds/60);
    	document.getElementById("debug").innerHTML+="<br>M "+minutes;
    	var hours=Math.floor(minutes/60);
    	document.getElementById("debug").innerHTML+="<br>H "+hours;
    	var days=Math.floor(hours/24);
    	document.getElementById("debug").innerHTML+="<br>D "+days;
    	var remainingseconds=seconds-(minutes*60);
    	document.getElementById("debug").innerHTML+="<br>RS "+remainingseconds;
    	var remainingminutes=minutes-(hours*60);
    	document.getElementById("debug").innerHTML+="<br>RM "+remainingminutes;
    	var remaininghours=hours-(days*24);
    	document.getElementById("debug").innerHTML+="<br>RH "+remaininghours;
    	
    	if(days<10){ days="0"+days; }
    	if(remaininghours<10){ remaininghours="0"+remaininghours;}
    	if(remainingminutes<10){ remainingminutes="0"+remainingminutes;}
    	if(remainingseconds<10){ remainingseconds="0"+remainingseconds;}
    	
    	document.getElementById("days").innerHTML=days;
    	document.getElementById("hours").innerHTML=remaininghours;
    	document.getElementById("minutes").innerHTML=remainingminutes;
    	document.getElementById("seconds").innerHTML=remainingseconds;
    	document.getElementById("currentsecondscount").value=(current-1);
    }
    </script>
    .......
    <input type="hidden" id="currentsecondscount" value="<?=$seconds;?>" />
    .......
    Chrome/IE/etc on Left... FF 3.6.3 [windows] on Right


    im not sure why Firefox is doing this. it seems to work fine on Firefox 3.6.3 for Mac...

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,938
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    doing what???

    What are we supposed to see?

    Looks to me like 340617 seconds is, indeed, 3 days 22 hours 36 minutes 57 seconds.

    What's wrong with that???

    I would have coded that more simply:
    Code:
    function countItDown()
    {
        var csc = document.getElementById("currentsecondscount");
        var secs = parseInt(csc.value);
        csc.value = secs - 1;
        var days = Math.floor( secs / 86400 );  // 86400 is 24 * 60 * 60
        var hrs = Math.floor( ( secs %= 86400 ) / 3600 ); 
        var mins = Math.floor( ( secs %= 3600 ) / 60 );
        secs %= 60; 
        document.getElementById("days").innerHTML = ( days < 10 ? "0" : "" ) + days;
        document.getElementById("hours").innerHTML = ( hrs < 10 ? "0" : "" ) + hrs;
        document.getElementById("minutes").innerHTML = ( mins < 10 ? "0" : "" ) + mins;
        document.getElementById("seconds").innerHTML = ( secs < 10 ? "0" : "" ) + secs;
    }
    But that's me.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    it is not supposed to be 340617 seconds as you can see on IE and Chrome and even FF on Mac, the # of seconds given by PHP (the very last line on the image i posted) seems to be getting 34.5 minutes or so added to it on FF

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    im not sure why but your script doesnt do the adding of 34.5 minutes. thanks

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,938
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Ahhh... You sure that's not a PHP problem???

    Suggestion:

    *Temporarily* put in a return at the front of that function:
    Code:
    function countItDown(){
        return; 
        ... existing code ...
    And then load up the page in FF.

    And then click on the VIEW menu of FF and then on the PAGE SOURCE menu item.

    Find your line that has
    Code:
    <input type="hidden" id="currentsecondscount" value="<?=$seconds;?>" />
    And show us what that looks like in the HTML page, after being rendered by PHP.

    If that shows the wrong value, then of course this has nothing to do with JavaScript.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    it wasnt a php issue otherwise it would be doing it on all the browsers. but your version works perfectly not sure what was so wrong about mine, albeit the long way around lol

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,938
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Quote Originally Posted by boeing747fp View Post
    im not sure why but your script doesnt do the adding of 34.5 minutes. thanks
    WOW! Now *THAT* is mysterious!

    The only big difference I can see is that I used parseInt() in place of your parseFloat() call at the start.

    So I *would* like to see what the HTML looks like that PHP is generating for that hidden field. It looks like parseFloat( ) is messing up, and I'd like to figure out why.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    i started with parseInt it did it for that too. i tried parseFloat to see if it changed but it didnt.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,938
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    I don't think it's directly PHP. Just thinking maybe the string value that PHP is dumping into the HTML is weird in some way, that's why I'd look at the HTML, were I you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    right now the output is
    Code:
    <input type="hidden" id="currentsecondscount" value="333788" />
    PHP Code:
    $month=6//numerical value of month (1-12)
    $day=22//numerical value of day (1-31)
    $year=2010//year
    $hour=14//hour without leading zeros (1-24)
    $minute=5//minute without leading zeros (0-59)
    $second=0//second without leading zeros (0-59)

    $time=mktime($hour,$minute,$second,$month,$day,$year);
    $seconds=$time-time(); 

  • #11
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    the weirdest part is that it worked fine in FF 3.6.3 for Mac but 3.6.3 for Windows was adding 34.5 minutes... and i cant figure out why. but im glad it's working now. thanks!

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,938
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Chalk this one up to fireflies, I guess. (Appropriate kind of bugs for firefox, of course.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    oooo i see what the problem was. the hidden field value was being cached and refresh wasnt clearing it

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,938
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    WOW! An agressive cache by FF! Wonder why it wasn't similarly cached on the Mac???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    either cache or autocomplete. i set autocomplete=off to the <input> and
    PHP Code:
    header("Cache-Control: no-cache, must-revalidate"); 
    it works now anyhow. thanks


  •  

    Posting Permissions

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