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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help combining....

    I am a newbie looking for a little bit of coding help. I have a count up script I'm using on my site. Here is an example of it:

    http://stempy.bravehost.com/cu.html

    Here is the actual script:

    <script type="text/javascript">
    var baseDate = "2005 September 30 09:05";
    var message = "since Stempy passed away, yet there has been NO JUSTICE for his preventable death."
    function dispCounter(){
    var refDate = new Date(baseDate);
    var currDate = new Date();
    var elapsedTime = currDate-refDate;
    var nDays = parseInt(elapsedTime/86400000);
    var nHours = parseInt((elapsedTime-(nDays*86400000))/3600000);
    var nMin = parseInt((elapsedTime-(nDays*86400000)-(nHours*3600000))/60000);
    var nSec = currDate.getSeconds();
    var nYears = parseInt(nDays/365);
    var nMonths = parseInt((nDays-(nYears*365))/30);
    var rDays = parseInt((nDays-(nYears*365)-(nMonths*30)));
    var cYears = "year";
    if (nYears != 1){cYears += "s,"} else {cYears += ","}
    cMonths = "month";
    if (nMonths != 1){cMonths +="s,"} else {cMonths += ","}
    var cDays = "day";
    if (rDays != 1){cDays += "s,"} else {cDays += ","}
    var cHours = "hour";
    if (nHours != 1){cHours += "s,"} else {cHours += ","}
    var cMinutes = "minute";
    if (nMin != 1){cMinutes += "s,"} else {cMinutes += ","}
    var cSeconds = "second";
    if (nSec != 1){cSeconds += "s,"} else {cSeconds += ","}
    document.getElementById('elapsed').innerHTML = "It's been "+nYears+" "+cYears+" "+nMonths+" "+cMonths+" "+rDays+" "+cDays+" "+nHours+" "+cHours+" "+nMin+" "+cMinutes+" and "+nSec+" "+cSeconds+"<br>"+ message
    setTimeout("dispCounter()",1000)
    }
    window.onload=dispCounter;
    </script>

    What I am wanting to do is insert this into a chart /table like this example, only it includes an extra box for months:

    http://www.jsmadeeasy.com/javascripts/Clocks%20And%20Date/Count%20Up%20From%20Date/index.htm
    I want to use the first script, but would like it diplayed like the second script. Any help would be appreciated.
    Last edited by gregm65; 01-01-2008 at 03:30 PM.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,468
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    var baseDate = "2005 September 30 09:05";
    function dispCounter(){
    var refDate = new Date(baseDate);
    var currDate = new Date();
    var elapsedTime = currDate-refDate;
    var nDays = parseInt(elapsedTime/86400000);
    var nHours = parseInt((elapsedTime-(nDays*86400000))/3600000);
    var nMin = parseInt((elapsedTime-(nDays*86400000)-(nHours*3600000))/60000);
    var nSec = currDate.getSeconds();
    var nYears = parseInt(nDays/365);
    var nMonths = parseInt((nDays-(nYears*365))/30);
    var rDays = parseInt((nDays-(nYears*365)-(nMonths*30)));
    var frm=document.clock;
    frm.years.value= nYears;
    frm.months.value= nMonths;
    frm.days.value= rDays;
    frm.hours.value= nHours;
    frm.mins.value= nMin;
    frm.secs.value= nSec;
    setTimeout("dispCounter()",1000)
    }
    
    window.onload=dispCounter;
    </script></head>
    
    <body>
    </font>
    <div id="elapsed" style="height: 92px;">since Stempy passed away, yet there has been NO JUSTICE for his preventable death.</div>
    <form name="clock">
    <table border=3>
    
    <tr>
    <td>Years:</td>
    <td>Months:</td>
    <td>Days:</td>
    <td>Hours:</td>
    <td>Mins:</td>
    <td>Secs:</td>
    </tr>
    
    
    <tr>
    <td><input name="years" size="4"></td>
    <td><input name="months" size="4"></td>
    <td><input name="days" size="4"></td>
    <td><input name="hours" size="4"></td>
    <td><input name="mins" size="4"></td>
    <td><input name="secs" size="4"></td>
    </tr>
    </table></form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • Users who have thanked vwphillips for this post:

    gregm65 (01-02-2008)

  • #3
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you, Vic! I certainly do appreciate it! See the end result here:

    http://stempy.bravehost.com/

    Greg.


  •  

    Posting Permissions

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