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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:56:19+00:00 2026-05-20T09:56:19+00:00

Okay, first some background, I can’t use any javascript library except YUI for this

  • 0

Okay, first some background, I can’t use any javascript library except YUI for this project.

What I’m trying to do is take an input and block it to only allow numeric input. I know this is easier to just do in validation, but the PM wants it onkeypress. What I have was constructed from running around the net and works great in firefox. Unfortunately, this has to be compatible with IE8 and IE6, and it works in neither.

Here is what I have so far:

<script type="text/javascript">
    function onlyNumbers(evt) {
        evt = (evt) ? evt : window.event
        var charCode = (evt.which) ? evt.which : event.keyCode        

        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

        return true;

    }
</script>
<input type="text" id="<%=Model.HtmlID %>" value="<%= startingAnswer %>"name="<%=Model.HtmlID %>"
 maxlength="<%=maximumLength %>" onkeypress="return onlyNumbers(event);" />

Any ideas on what is wrong with it that is making it not work in IE?

  • 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-20T09:56:20+00:00Added an answer on May 20, 2026 at 9:56 am
    <script type="text/javascript">
        function onlyNumbers(target) {
            var newVal = document.getElementById(target).value;
            if (isNaN(newVal)) {
                document.getElementById(target).value = newVal.replace(/[^0-9.]/g, "");
            }
        }
    
    
    </script>
    <input type="text" id="<%=Model.HtmlID %>" value="<%= startingAnswer %>"name="<%=Model.HtmlID %>"
     maxlength="<%=maximumLength %>" onkeyup="javascript:onlyNumbers('<%=Model.HtmlID %>');" />
    

    It took some extra effort, and a little creativity, but I did get this one figured out. This doesn’t really disallow the input, instead it simply wipes out anything that isn’t allowed as soon as you let go of the key. Actually works on IE6 too

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

Sidebar

Related Questions

Okay, first I will begin with some background. I'm working on a project for
Okay at first I thought this would be pretty straightforward. But I can't think
Okay, I'm trying to be clear on this one... I have some insliding boxes,
Okay, I am trying to integrate some C code into a C++ project, and
Okay this is my first WPF app and I am having a hard run
First off, I'm using XCode 4.0.2. Okay, here is my issue. I can build
first, I can't stand Crystal! Okay, that's off my chest... Now, we have an
OKay first off this is really really similiar to the http://dribbble.com homepage. In the
Well Im stucked at this point.please take a look at this http://jsfiddle.net/karthik64/5jhgF/3/ Okay first
Okay,...first the facts. I'm working on an ASP.Net project which validates it's users across

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.