user918477
user918477

Reputation:

input box taking numeric value in firefox

Using this code, user won't enter numeric value. In Google Chrome, input box is not taking numeric value but in Firefox it takes. I'm not getting, why it is happening. Any help appreciated.

<input type="text" name="station_name" id="station_name" onKeyPress="return noNumbers(this)" maxlength="45" />

this is my javascript function

<script type="text/javascript" language="javascript">
 function noNumbers(evt)
            {
                var charCode = (evt.which) ? evt.which : event.keyCode;
                if((charCode>=65 && charCode<=90)||(charCode>=97 && charCode<=122)||(charCode==32))
                    return true;
                return false;
            }
</script>

Upvotes: 0

Views: 217

Answers (2)

Vikram
Vikram

Reputation: 8333

you are passing this in the following line, pass event

<input type="text" name="station_name" id="station_name" onKeyPress="return noNumbers(event)" maxlength="45" />

EDIT ok try the follwoing function and the input tag as above:

function noNumbers(evt)
            {
                var charCode = evt.keyCode || evt.which;
                if((charCode>=65 && charCode<=90)||(charCode>=97 && charCode<=122)||(charCode==32)||||(charCode==8))
                    return true;
                return false;
            }

Upvotes: 1

Pranay Rana
Pranay Rana

Reputation: 176936

This is because, in Firefox, the event is passed as a parameter to the event handler. event property of the window object is IE only.

function enterHere(e)
{
    e = e || window.event;
    var code = e.keyCode || e.which;
    if(code == 13)
        find();
}

Upvotes: 2

Related Questions