View Full Version : DD Countup Script: Thousands (Comma) Separator?
MissKitty
07-23-2007, 03:07 PM
1) Script Title:
Dynamic Countup Script
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex6/countingup.htm
3) Describe problem:
This works great - only problem is formatting the thousands with a comma separator?
Thanks in advance!
ddadmin
07-24-2007, 12:41 AM
There are many premade functions online that format a number with comma separators, for example, this one (http://www.mredkj.com/javascript/nfbasic.html). Using it, add the below function to the original script first:
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
Then, inside the oncountup event handler, pass the "days" field into this function for processing first:
princewedding.oncountup=function(result){
//result is an object containing the current count up date/time, updated every second
//Available properties: result["days"], result["hours"], result["minutes"], and result["seconds"]
result["days"]=addCommas(result["days"])
var mycountainer=document.getElementById("cpcontainer")
mycountainer.innerHTML="Prince Charles and Camilla Parker have been married for: <br /><span class='dcountstyle'>"+result['days']+" <sup>days</sup> "+result['hours']+" <sup>hours</sup> "+result['minutes']+" <sup>minutes</sup> "+result['seconds']+" <sup>seconds</sup></span>"
}
MissKitty
07-24-2007, 04:52 PM
Thank you very much!
the DD scripts are a godsend, I love it! :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.