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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:14:50+00:00 2026-05-26T12:14:50+00:00

This was an example from our prof and my HTML is rusty so I’m

  • 0

This was an example from our prof and my HTML is rusty so I’m not sure exactly what is going on.
For the form input:

<input type="text" name="widgets" id="widgets" size="2" value="0" onchange="calc();" onkeypress="return isNumberInput(this, event);" />

For the Javascript:

function isNumberInput(field, event)
{
var key, keyChar;
if (window.event)
key = window.event.keyCode;
else if (event)
key = event.which;
else
return true;
// Check for special characters like backspace
if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
return true;
// Check to see if it.s a number
keyChar = String.fromCharCode(key);
if (/\d/.test(keyChar))
{
window.status = "";
return true;
}
else
{
window.status = "Field accepts numbers only.";
return false;
}

Can someone explain what is going on? I’m not too familiar with window.event, event.which, wondow.event.keyCode, etc. I don’t really understand the logic. TIA!

  • 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-26T12:14:51+00:00Added an answer on May 26, 2026 at 12:14 pm
    var key, keyChar; // declare variable to be used
    if (window.event) // window.event Microsoft uses window.event. Does it exist? If so continue
        key = window.event.keyCode; // Microsoft uses window.event.keyCode to get the key the was pressed
    else if (event) // other modern browsers will create an event object for you to use
        key = event.which; // event.which is the key that was pressed
    else // else we can't get to the key maybe this is a full text browser? Anyways, no good exit function
        return true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Someone from our team change the permalink of a page to http://www.example.com/ so this
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval
In this example from the App Engine docs , why does the example declare
I tried to copy this example from this Multiprocessing lecture by jesse noller (as
With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
Why in this example from MSDN, in GetEnumerator method, PeopleEnum returns IEnumerator ? public
thank you for looking i got this example from my book but i cant
I am trying to follow this example (from p137 of Rob Pickering's Foundations of
Can someone explain how New works with the With keyword in this example from
This example is from php.net: <?php function Test() { static $a = 0; echo

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.