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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:54:12+00:00 2026-05-30T10:54:12+00:00

Im working on a simple html/javascript multiplication game, in which I have a multiplication

  • 0

Im working on a simple html/javascript multiplication game, in which I have a multiplication table with some inputs that represet the results of the products. in that game, you need to answer as fast as you can on as many questions as you can. to make it easy on the players, ive assign an event to the enter key to move to the next input when it is pressed.

multiplication table game

Here is the javascript code for highlighting the rows and the enter key event:

for (var i=0; i<boardInputArray.length; i++) {
    boardInputArray[i].onkeydown = (function(nextBox) {
        return function(e) {
            if(e.keyCode == 13) {
                if(nextBox==boardInputArray.length) {boardInputArray[0].focus();boardInputArray[0].select();}
                else {boardInputArray[nextBox].focus();boardInputArray[nextBox].select();}
                var gameCompleted = true;
                for(var c=0;c<boardInputArray.length;c++) {
                    if(boardInputArray[c].value == '') {gameCompleted = false;}
                }
                if(gameCompleted) validateGame();
            }
        }
    })(i+1);
}

I dont want to post the entire code here, because it is very long. If you would like to see the game in action, go to:
http://www.webdesk.co.il/articles/javascript/multiplication-table-game.php

Here’s the problem: I would like that each time the Enter key is pressed, it will check if the following input is empty or not. in case its not empty – skip to the next one and so on until it finds an empty input. That way, the player can go back to the question he didnt answer and not go through all the ones he did answer. makes sense?

  • 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-30T10:54:14+00:00Added an answer on May 30, 2026 at 10:54 am

    You can probably improve this code, but it does take care of moving to the next empty box.

    for (var i=0; i<boardInputArray.length; i++) {
        boardInputArray[i].onkeydown = (function(currentBox) {
            return function(e) {
                if(e.keyCode == 13) {
                    var gameCompleted = true;
                    if(boardInputArray[currentBox].value == '')
                        gameCompleted = false;
                    for (
                            var c = (currentBox + 1) % boardInputArray.length;
                            c != currentBox;
                            c = (c + 1) % boardInputArray.length
                        )
                    {
                        if(boardInputArray[c].value == '')
                        {
                            gameCompleted = false;
                            boardInputArray[c].focus();
                            boardInputArray[c].select();
                            break;
                        }
                    }
                    if(gameCompleted) validateGame();
                }
            }
        })(i);
    }
    

    Notes:

    • I’ve made the anonymous function a function of currentBox instead of nextBox (i instead of i + 1).
    • The loop goes through all the boxes except the current box, by starting at the next box, wrapping around and ending at the previous box or when it encounters a blank box.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a simple JavaScript validation function for a html form, but have
I have a very simple JavaScript operation which is just not working. I'm using
I'm working on a simple multiplayer game in which 2-4 players are placed at
I'm working on a simple javascript login for a site, and have come up
I have this simple HTML: <span class=coverImg style=background-image:url('images/show2.jpg');></span></a> and some Javascript: $(function() { $(.coverImg).hover(function()
I have a simple html form that I've added validation to using the JQuery
I am working on a simple Rails/jQuery HTML templater app which stores a series
I have a very simple demo working that uses Webkit transforms and transitions for
I have a simple html page that only uses PHP in two places <?php
Im working on a HTML test page with a simple grid that has red

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.