Block numbers from being entered in an input field
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?
Block numbers from being entered in an input field
===

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?