Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Auto incrementing number
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedAuto incrementing number

 Post Reply Post Reply
Author
normie View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: Australia
Status: Offline
Points: 2
Direct Link To This Post Topic: Auto incrementing number
    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

Back to Top
..::PeDRo::.. View Drop Down
Newbie
Newbie


Joined: 19 July 2003
Location: Australia
Status: Offline
Points: 4
Direct Link To This Post Posted: 22 July 2003 at 6:28am

What did you need it for?

Counter, users online, downloads, etc?

Back to Top
normie View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: Australia
Status: Offline
Points: 2
Direct Link To This Post 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>

Back to Top
..::PeDRo::.. View Drop Down
Newbie
Newbie


Joined: 19 July 2003
Location: Australia
Status: Offline
Points: 4
Direct Link To This Post 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!!

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.