View Full Version : firefox math messing up somehow?

06-18-2010, 11:12 PM
<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;}

<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... :(

Old Pedant
06-19-2010, 12:08 AM
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:

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.

06-19-2010, 12:10 AM
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 :(

06-19-2010, 12:18 AM
im not sure why but your script doesnt do the adding of 34.5 minutes. thanks

Old Pedant
06-19-2010, 12:18 AM
Ahhh... You sure that's not a PHP problem???


*Temporarily* put in a return at the front of that function:

function countItDown(){
... 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

<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.

06-19-2010, 12:20 AM
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

Old Pedant
06-19-2010, 12:20 AM
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.

06-19-2010, 12:21 AM
i started with parseInt it did it for that too. i tried parseFloat to see if it changed but it didnt.

Old Pedant
06-19-2010, 12:21 AM
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.

06-19-2010, 12:22 AM
right now the output is

<input type="hidden" id="currentsecondscount" value="333788" />

$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)


06-19-2010, 12:26 AM
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!

Old Pedant
06-19-2010, 12:29 AM
Chalk this one up to fireflies, I guess. (Appropriate kind of bugs for firefox, of course.)

06-19-2010, 12:35 AM
oooo i see what the problem was. the hidden field value was being cached and refresh wasnt clearing it

Old Pedant
06-19-2010, 12:43 AM
WOW! An agressive cache by FF! Wonder why it wasn't similarly cached on the Mac???

06-19-2010, 12:43 AM
either cache or autocomplete. i set autocomplete=off to the <input> and
header("Cache-Control: no-cache, must-revalidate");

it works now anyhow. thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum