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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:40:29+00:00 2026-05-27T08:40:29+00:00

last night I was coding a little piece of JS code that records the

  • 0

last night I was coding a little piece of JS code that records the number of mouse clicks on a keypad (akin to a mobile phone) and with each successive press a new value would be entered into a textbox. This is how I’ve got so far.

The difficulty last night was that I set count as a global variable which was carried across meant if a user clicked on 1 and 2 they would get 1D in the text box when they should be getting 12:

http://jsfiddle.net/JNCCW/7/

In my most recent code I’ve tried to create an array so initially we have:

[0,0,0,0]

And each time the user clicks a button then e.g 1 and then 2 – the array updates to:

[1,1,0,0]

The values at 1 in array 1,2 are then added to the text box.

When the array element equals 4 then the array element resets to 0.

http://jsfiddle.net/JNCCW/9/

I’ve been having difficulty achieving this and feel that the logic behind my coding is awkward. I would appreciate any help!

  • 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-05-27T08:40:30+00:00Added an answer on May 27, 2026 at 8:40 am

    You need to store the id of element where you start counting index:

    var count = 0
    var elId;
    function input(number) {
        if (elIf != number) {
            elId = number;
            count = 0;
         }
    
        number = number.split(".");
        document.getElementById('search').value += number[count];
        count++;
        if (count == 4) {
            count = 0;
        }
    }
    

    http://jsfiddle.net/JNCCW/15/

    update: http://jsfiddle.net/JNCCW/19/

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

Sidebar

Related Questions

Update: Last night, I decided that this is just too much work to change
Last night I did a load test on a site. I found that one
Last night one of our users identified an issue with a site that hasn't
I posted last night stating that I was creating a Windows Service with the
I began using WCF last night to setup a simple client server that will
Last night I had dream that the following was impossible. But in the same
Last night I was thining that programming languages can have a feature in which
This bug tricked me into spending 4 hours debugging perfectly functional code last night.
Last night I was at a Boston Python Meetup that described various Python implementations.
So I was creating a small project for fun last night that involves creating

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.