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

  • Home
  • SEARCH
  • 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 9221779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:39:01+00:00 2026-06-18T03:39:01+00:00

Possible Duplicate: setInterval only runs once? Before I proceed let me say as a

  • 0

Possible Duplicate:
setInterval only runs once?

Before I proceed let me say as a designer logic comes difficultly, so I appreciate you bearing with my ignorance.

I am making a simple slider, and I would like it so that when the user moves the picture with their mouse the program can make note of the distance covered in the last second before mouseup(), so that in turn I can calculate how much the picture has to travel to simulate as though it was swiped.

I’ve got my base event handlers as so:

$('.testdiv').mousedown(function(){

    pretestFunction();

    //mouse is pressed
    mousepressed = 1;

    //set first X point
    prevX = event.pageX;


}).mouseup(function(){

    //get stop X point
    stopX = event.pageX;
    mousepressed = 0;

});

pretestFunction calls setInterval, like so:

function pretestFunction(){
    window.setInterval(testFunction(), 1000);
}

testfunction():

function testFunction(){
    console.log('1 second');
}

My problem is that the set interval function is only called once, and not once every second like I am trying to get it to do. What am I doing wrong?

  • 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-18T03:39:03+00:00Added an answer on June 18, 2026 at 3:39 am
    window.setInterval(testFunction(), 1000);
    

    should be

    window.setInterval(testFunction, 1000);
    

    In the first, you are passing the value of calling testFunction (which happens to be undefined, but thats not important)

    In the second you would be passing the value of testFunction (i.e. a function, which is what you want.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: setInterval() only running function once I'm using the following script to understand
Possible Duplicate: What to do when I want to use database constraints but only
Possible Duplicate: Is there a way to check if a var is using setInterval()
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Let's
Possible Duplicate: How can I clearInterval() for all setInterval()? I called setInterval in my
Possible Duplicate: Stop setInterval call in javascript I use window.setInterval method for polling progress
Possible Duplicate: JS - How to clear interval after using setInterval() I have a
Possible Duplicate: Why does Twitter redefine window.setTimeout and window.setInterval? I saw a code like
Possible Duplicate: function in setInterval() executes without delay I am trying to use setTimeOut
Possible Duplicate: How can I make setInterval also work when a tab is inactive

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.