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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:41:09+00:00 2026-05-17T14:41:09+00:00

I am completely confused here. So I am looking for a solution for the

  • 0

I am completely confused here. So I am looking for a solution for the following problem:

I want to trigger some function(for now an alert box) using jQuery on an input field. Conditions are:

  • Input field always maintains the focus.
  • Input is fed from a USB device, which acts just like a keyboard input. So for 10 characters, there will be 10 keydown and keyup events.
  • Once input is filled with 10 characters, respective alert box should pop out.

Now the problem I am facing, how do I find out that input fed in is not equal to 10 characters, so throw an error alert box.(lets say just 5 chars came in input, how do I figure out the final count is 5, because there will be 5 keyup events)

  • 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-17T14:41:09+00:00Added an answer on May 17, 2026 at 2:41 pm

    You really have two problems here. One is just understanding the jQuery syntax (see the second part to my answer), and the other is – what is the best way to understand WHEN to throw up an error box.

    To answer the second question first, my recommendation would be to not use an alert box to warn the user as they tend to be modal and really interrupt the flow of input. Secondly, as you said – how do you know when the person has stopped “typing.” Unless you use some sort of timing mechanism (which is more trouble than it’s worth), you don’t. My suggestion would be to utilize a “div” within your HTML that shows there is an error UNTIL you reach 10 characters. Once that happens, you can hide the div. (And, of course, the div can be styled to look pretty in the meantime.)

    So…how to do this…

    Let’s assuming your input field has an id of “myField.” If you are using jQuery (which is in your tags), you would do something like this.

    $(function() {
      var keypresses = 0;
      $('#myField').keyUp(function () {
        keypresses++;
        if(keypresses == 10) {
          $('#error').hide(); // This is your div error with some error text in it.
          // Do other stuff.
        } else {
          // Display an error.
        }
      });
    

    Alternatively, if you don’t want to use the keypresses variable, you can also use..

    if($(this).val().length == 10) { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm being completely confused here folks, My code throws an exception because File.Exists() returns
I want completely automated integration testing for a Maven project. The integration tests require
I've almost completely installed Boost, but I have a problem with how to set
I've recently updated to a testing distribution, which is now using GCC 4.4.3. Now
I'm having trouble implmenting the 3rd parameter in the function documented here: http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/reference/async_read_until/overload4.html What
I am trying to grok Mercurial and hope I am just getting confused here!
Given the following declaration: <Extension()> Public Function ToJSON(ByVal target As Object) As String Dim
I have managed to get myself confused about some elements of memory management. I
I'm a little confused here. I have my POCO classes created with the entity
I completely understand the concept of expression trees, but I am having a hard

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.