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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:28:37+00:00 2026-06-12T20:28:37+00:00

I am learning about javascript from the book JavaScript Bible, but I have some

  • 0

I am learning about javascript from the book “JavaScript Bible”, but I have some difficulties.
I’m trying to understand this code:

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accept only numbers."
        return false
    }
    status = ""
    return true
}

Someone can explain to me?

  • 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-12T20:28:38+00:00Added an answer on June 12, 2026 at 8:28 pm

    I assume that you just want us to explain what the code does. If so, see below:

    // Create a function named checkIt, which takes an argument evt.
    function checkIt(evt) {
    
        // If the user has passed something in the argument evt, take it.
        // Else, take the window.event as evt.
        evt = (evt) ? evt : window.event;
    
        // Get the Character Code. It can be either from evt.which or evt.keyCode,
        // depending on the browser.
        var charCode = (evt.which) ? evt.which : evt.keyCode;
    
        // If the Character is not a number, the do not allow the user to type in.
        // The reason for giving 31 to 48 and greater than 57 is because, each key
        // you type has its own unique character code. From 31 to 48, are the numeric
        // keys in the keyboard.
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    
            // Give a status informing the user.
            status = "This field accept only numbers.";
    
            // Prevent the default action of entering the character.
            return false;
        }
    
        // Clear the status
        status = "";
    
        // Allow the user to enter text.
        return true;
    }
    

    ASCII Code Reference


    (source: cdrummond.qc.ca)


    (source: cdrummond.qc.ca)

    PS: I edited your code adding semi-colons ; which were missing.

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

Sidebar

Related Questions

Learning Javascript and have a question about global variables. From my reading, most recommend
I have been learning the Definitive Guide of JavaScript.i got a question about the
I am learning Javascript, I have been using PHP for about 10 years so
I am thinking about learning Clojure, but coming from the c-syntax based (java, php,
I am learning javascript sample from this page and I am using IE 7
I am learning javascript sample from this page, http://nofunc.org/AJAX_Star_Rating my questions are (1), for
I am learning about backbone, and from the examples and tutorials I have gotten
This may be very convoluted and twisted idea. Got it while learning some JavaScript.
This is really for informational and learning purposes while learning more about JavaScript and
I'm just messing around learning about JavaScript and I wanted to change the color

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.