1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Javascript Help

Discussion in 'General Programming Chat' started by judif414, Jul 21, 2014.

  1. judif414

    judif414 Regular Member

    Joined:
    Feb 25, 2013
    Messages:
    488
    Likes Received:
    438
    Hey guys hope some programmers can help out.

    I need a javascript counter that can count from a number I specify (ex. 435) and update every 1-4 seconds (randomly).

    Also needs to increase by 1. Would like to add some text in there as well if possible.

    Much appreciated!
     
  2. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    75
    Hey there mate

    For this task you would do good in using setTimeout() function (http://www.w3schools.com/jsref/met_win_settimeout.asp), where you will grab the html element and set the new value. For example:

    You need to change the use jQuery, change the jQuery selector and choose the starting counter.

    Cheers
     
    • Thanks Thanks x 1
  3. judif414

    judif414 Regular Member

    Joined:
    Feb 25, 2013
    Messages:
    488
    Likes Received:
    438
    Thanks man, looks good. I just don't know how to implement it with html.

    Can anyone else help?

    I'm trying to implement the above code into a simple html landing page.
     
  4. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    75
    Hey,

    It depends on the kind of site and what you're specifically trying to accomplish. I know for sure there are a lot of free jQuery plugins that do what you ask for for free.
     
    • Thanks Thanks x 1
  5. judif414

    judif414 Regular Member

    Joined:
    Feb 25, 2013
    Messages:
    488
    Likes Received:
    438
    Gotcha.

    This is what I want to do exactly.

    I want the counter to go up (like I described in the first post) instead of being static like this:

    Code:
    <span class="downloads">531 Downloads<img src="img/downloadimage.png" alt="downloads" />
    BTW, it's just an html template, nothing fancy.

    Thanks again for the help!
     
  6. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    75
    Oh, OK,

    Then just add this up:

    Hope it helps
     
    • Thanks Thanks x 1
  7. judif414

    judif414 Regular Member

    Joined:
    Feb 25, 2013
    Messages:
    488
    Likes Received:
    438
    Thanks again, just not sure where to put the code? Do I put it inside the <span> </span> tags?

    Thanks
     
  8. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    75
    No, just anywhere before you close the <body> tag, outside of any other tag, other than <script>
     
    • Thanks Thanks x 1
  9. judif414

    judif414 Regular Member

    Joined:
    Feb 25, 2013
    Messages:
    488
    Likes Received:
    438
    AWESOME, got it to work! Wow appreciate all the help!
    Thanks!
     
  10. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    75
    Sure, it's nothing, glad I could help :)
     
    • Thanks Thanks x 1