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 7725581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:58:29+00:00 2026-06-01T04:58:29+00:00

I am trying to consecutively add +1 to the value of a text input

  • 0

I am trying to consecutively add +1 to the value of a text input field when the user clicks a button.

Simplified, my JQuery code is something like this:

$('#button').on({
 mousedown : function () {
 var value = $(this).val();
 $(this).val(value + 1);
 },
 mouseup : function () {
 //Some other stuff here
 }
});

This works every time the user clicks the button.
What I want is if the user keeps the button pressed, the mousedown event to fire every 0.2s until he stops pressing (and than the mouseup event fires).

I figure this should somehow be done with setTimeout() but I would be glad if someone showed me how. Thanks.

  • 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-01T04:58:30+00:00Added an answer on June 1, 2026 at 4:58 am

    Use setInterval and clearInterval:

    var interval;
    $('#button').on({
      mousedown : function () {
        var el = $(this);
        el.val(parseInt(el.val(), 10) + 1);
        interval = window.setInterval(function(){
          el.val(parseInt(el.val(), 10) + 1);
        }, 200);
      },
      mouseup : function () {
        window.clearInterval(interval);
      }
    });
    

    However, it’s not possible to run as often as every 0.2 ms, I suppose that you mean every 0.2 seconds…

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

Sidebar

Related Questions

I'am trying to delete words which have 2 capital letters consecutively with MySQL. Like:
I'm trying to extract two blocks of code from a text file using Java
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
Trying to get a wildcard search to pick up on any text in org_name
I'm trying to just get rid of duplicate consecutive words from a text file,
I am trying some code around object equality in java. As I have read
I'm trying to run a stored procedure to add 3 consecutive books to a
I'm trying to create a loop like this newList = [a + b for
Trying to assemble a rather complex jQuery selector here, and having trouble. Essentially, I'm

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.