Print Page | Close Window

Auto incrementing number

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=4425
Printed Date: 29 March 2026 at 9:19am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Auto incrementing number
Posted By: normie
Subject: Auto incrementing number
Date Posted: 21 July 2003 at 5:18pm

Hi,

I want to be able to have a display on a page, that simply counts up according to my parameters.

 

I figure I should be able to do it with Javascripts.

Any ideas



-------------
Cheers
Normie



Replies:
Posted By: ..::PeDRo::..
Date Posted: 22 July 2003 at 6:28am

What did you need it for?

Counter, users online, downloads, etc?



-------------
..::PeDRo::..
http://www.users.bigpond.com/pedro676/ - ///////////\
Honest! It was like that when I got here...


Posted By: normie
Date Posted: 22 July 2003 at 4:36pm

I figured it out already.  Thanks anyway.

Basically I wanted a number on a page that counted up by x per day.  Kinda like a Hamburgers sold since 1966 type of thing.

Here is the code. It if far more advanced than what I needed, and allows for more variables.  But I used the D section.

 

<script language="javascript">
   function suycDateDiff( start, end, interval, rounding ) {

    var iOut = 0;
      
    // Create 2 error messages, 1 for each argument.
    var startMsg = "Check the Start Date and End Date\n"
     startMsg += "must be a valid date format.\n\n"
     startMsg += "Please try again." ;
     
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
     intervalMsg += "d, h, m OR s intervals.\n\n"
     intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
        
    // check that the start parameter is a valid Date.
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
     alert( startMsg ) ;
     return null ;
    }
    
    // check that an interval parameter was not numeric.
    if ( interval.charAt == 'undefined' ) {
     // the user specified an incorrect interval, handle the error.
     alert( intervalMsg ) ;
     return null ;
    }
      
    var number = bufferB-bufferA ;
      
    // what kind of add to do?
    switch (interval.charAt(0))
    {
     case 'd': case 'D':
      iOut = parseInt(number / 86400000) ;
      if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
      break ;
     case 'h': case 'H':
      iOut = parseInt(number / 3600000 ) ;
      if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
      break ;
     case 'm': case 'M':
      iOut = parseInt(number / 60000 ) ;
      if(rounding) iOut += parseInt((number % 60000)/30001) ;
      break ;
     case 's': case 'S':
      iOut = parseInt(number / 1000 ) ;
      if(rounding) iOut += parseInt((number % 1000)/501) ;
      break ;
     default:
     // If we get to here then the interval parameter
     // didn't meet the d,h,m,s criteria.  Handle
     // the error.   
     alert(intervalMsg) ;
     return null ;
    }
      
    return iOut ;
   }


  function dateDifference(strDate1,strDate2, interval, rounding)
   {
    datDate1= Date.parse(strDate1);
    datDate2= Date.parse(strDate2);

    var iOut = 0;
    var number = datDate2-datDate1 ;

    // what kind of add to do?
    switch (interval.charAt(0))
    {
     case 'd': case 'D':
      iOut = parseInt(number / 86400000) ;
      if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
      break ;
     case 'h': case 'H':
      iOut = parseInt(number / 3600000 ) ;
      if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
      break ;
     case 'm': case 'M':
      iOut = parseInt(number / 60000 ) ;
      if(rounding) iOut += parseInt((number % 60000)/30001) ;
      break ;
     case 's': case 'S':
      iOut = parseInt(number / 1000 ) ;
      if(rounding) iOut += parseInt((number % 1000)/501) ;
      break ;
     default:
      // If we get to here then the interval parameter
      // didn't meet the d,h,m,s criteria.  Handle
      // the error.   
      alert(intervalMsg) ;
     return null ;
    }
    return iOut ;
   }

  function displayCounter()
  {
  var intStartCount = 8000
  var strDisplay
  var initialDate = new Date(2003,6,1);
  var currentDate = new Date()
 
  if (currentDate.getHours() > 12)
   {
    strDisplay = suycDateDiff(initialDate, currentDate, 'd', true) + intStartCount + 1
   }
  else
   {
    strDisplay = suycDateDiff(initialDate, currentDate, 'd', true) + intStartCount
   }
  
  document.getElementById('spnCounter').innerText = strDisplay;
  }
  </script>



-------------
Cheers
Normie


Posted By: ..::PeDRo::..
Date Posted: 22 July 2003 at 5:19pm

Yoink!

I'll take that thanks  may turn that into a nice timer of some sort

Ta Norm!!



-------------
..::PeDRo::..
http://www.users.bigpond.com/pedro676/ - ///////////\
Honest! It was like that when I got here...



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net