Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:12:40+00:00 2026-06-11T23:12:40+00:00

Updated with latest code: Here is the latest code, still has 2 buttons and

  • 0

Updated with latest code:

Here is the latest code, still has 2 buttons and 2 functions. Each button should run the relievant function and set the code to run the same button after every minute via the setInterval. For some reason, the very first setInterval always seems to stay set, even after clicking the second button which should change it. Not sure what I’m doing wrong:

$(document).ready(function() {
    var myTimer = null;

    get_popular();

    clearInterval(myTimer);
    myTimer = null;
    myTimer = setInterval(function() {$('a.btnPopular').click();}, 60*1000);

    $('a.btnPopular').click( function(event) {
        event.preventDefault(); 
        get_popular( $(this) );

        clearInterval(myTimer);
        myTimer = null;
        myTimer = setInterval(function() {$('a.btnPopular').click();}, 60*1000);
    });

    function get_popular( that ) {
        $.ajax({
            url: 'get_popular.aspx?rand=' + Math.random(),
            type: 'GET',
            error: function(xhr, status, error) {
                // error message here
            },
            success: function(results) { 
                if ( typeof that != "undefined" ) {
                    that.closest('.outer_div').find('.inner_div').empty().append( results );
                } else {
                    $('.inner_div.new').empty().append( results ).removeClass('new');
                }
            }
        });
    }

    $('a.btnLatest').click( function(event) {
        event.preventDefault(); 
        get_latest( $(this) );

        clearInterval(myTimer);
        myTimer = null;
        myTimer = setInterval(function() {$('a.btnLatest').click();}, 60*1000);
    });

    function get_latest( that ) {
        $.ajax({
            url: 'get_latest.aspx?rand=' + Math.random(),
            type: 'GET',
            error: function(xhr, status, error) {
                // error message here
            },
            success: function(results) { 
                if ( typeof that != "undefined" ) {
                    that.closest('.outer_div').find('.inner_div').empty().append( results );
                } else {
                    $('.inner_div.new').empty().append( results ).removeClass('new');
                }
            }
        });
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:12:41+00:00Added an answer on June 11, 2026 at 11:12 pm

    Try:

    setInterval(function() {$('a.btnPopular').click();}, 60*1000);
    

    Edit:
    Also you can’t call get_popular(); without a parameter 😉

    Edit 2:
    This should solve your problems:

    var myTimer = null;
    
    $('a.btnPopular').click(function(event) {
        event.preventDefault(); 
        get_popular($(this));
        clearTimeout(myTimer);
        myTimer = setTimeout(function(){$('a.btnPopular').click();}, 60*1000);
    });
    
    $('a.btnLatest').click(function(event) {
        event.preventDefault(); 
        get_latest($(this));
        clearTimeout(myTimer);
        myTimer = setTimeout(function(){$('a.btnLatest').click();}, 60*1000);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code i current have is this. function update (){ latest_id = $('#image:first').data('position'); /*
I'm using MPOAuthConnection for Cocoa oauth. I've updated the latest from SVN, built the
I've just updated to the latest build of cruisecontrol.net (1.5.0.5972). I've a few teething
I just updated virtualbox to the latest 4.1.16 r78094 and realized that I can
I am trying to get the swiping to work for Cocos2d latest version here
I'm running my app on shared hosting. When I run the latest changes on
I followed the instruction here: http://www.grails.org/doc/latest/guide/7.%20Validation.html and added into config.groovy : grails.validateable.classes = [liningtest.Warm']
I have following code in HomeController ; it gets latest date and shows songs
I have a script that I run in terminal that runs the scan-build code
I just updated to the latest Firefox (4) and now our Cucumber, Capybara and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.