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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:53:06+00:00 2026-05-30T05:53:06+00:00

I have this input text: 010 141 474 010 141 474 I want to

  • 0

I have this input text:

010 141 474 010 141 474

I want to press the above numbers in order that is presented, one by one. I use a flag to allow only one number at time, but it doesn’t work correct. In the code that is depict I can press both numbers firt, but I want first 0, second 1, third 0 etc… And what about with duplicates numbers? I duplicate the code? Also I thought to check if a button is onkeyup but nothing. Any help? Thanks in advance. My code:

function keyPressed(event){
var code;
var isKeyRepeating = false;
if(window.event){ //IE
code = event.keyCode;
}
else{ //other browsers
code = event.which;
}

if (code == 48 || code == 96){ //both keycodes for the same number  
 document.onkeypress("0");
 isKeyRepeating = true;
}

if (code == 49 || code == 97){   
 document.onkeypress("1");
 isKeyRepeating = true;
}

else {
   event.preventDefault();
   isKeyRepeating  = false;
}
}

input field:

 <input style="border-style: inset" size="90" type="text" name="key" id="txtboxToFilter" onkeypress="javascript:keyPressed(event);"/>
  • 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-30T05:53:07+00:00Added an answer on May 30, 2026 at 5:53 am

    Your question is most confusing. Typing one character at a time is completely trivial, unless you specifically want to prevent holding keys down. As such, I’m not sure what you even want.

    If you want the user to only be able to type the characters in the correct order, this will work for you:

    <script type="text/javascript">
    function keyPressed(event, input) {
        if (event.keyCode == 8) {
            // Allow backspace
            return true;
        }
        // Detect character code: event.which on Firefox, event.keyCode on IE
        var char = event.which ? event.which : event.keyCode;
        // Convert to string
        char = String.fromCharCode(char);
        var match = 'aBÁ 010 141 474 010 141 474';
        // Compare to character in match string and return result
        return (match.charAt(input.value.length) == char);
    }
    </script>
    
    <input size="30" type="text" name="key" id="txtboxToFilter" onkeypress="return keyPressed(event, this);"/>
    

    There is another answer which uses a similar function, but the critical difference is that it uses an onkeydown handler, which produces different results. One needs to understand that onkeydown deals with a single key pressed, while onkeypress deals with a single character typed. For example, if you type uppercase A, there are two keydown events: one for shift, another for a. There is however only one keypress event for A.

    Even more critical is that one cannot expect all key codes to match with character codes when using onkeydown. For example, the key codes for numbers are different if typed from the numpad, and the key codes for special characters are completely unreliable. Using onkeypress however, the key codes will match with character codes, if the key represents a visible character.

    Therefore, the deciding factor between using onkeydown or onkeypress is whether you wish to detect arbitrary key presses, or visible typed characters.

    (The following was part of the original answer, while it turned out it was not what the OP wanted, I’m leaving it here for reference).

    If you want the user to only be able to type number, this will do it:

    <script type="text/javascript">
    function keyPressed(event) {
        var char = event.which ? event.which : event.keyCode;
        char = String.fromCharCode(char);
        var regexp = /\d/;
        return regexp.test(char);
    }
    </script>
    
    <input size="30" type="text" name="key" id="txtboxToFilter" onkeypress="return keyPressed(event);"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this text input in a form, and I want to update
I have two things i want to do to this input text field. <input
I have saved input (text,checkbox,dropdownlist) in one html page, and am loading that in
I have input text element, I want: when I write some symbol in this
I have this input that has text and when you click it, the text
I have this input text and an input button...I am looking to have them
I have this input text and input button, I am trying to get them
trying to figure out why this is happening - I have an input text
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have a text input : <input type=text onkeydown=processText(this) /> I have a processing

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.