开发者

numeric validation not working in firefox

i have a textbox wh开发者_JAVA百科ich i need to accept only digits.All other keys in the keyboard sholdn't generate event in the textbox.i created a javascript code

<script type="text/javascript">
function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;

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

return true;
}
</script>

html is

<asp:TextBox ID="txtFreeship" runat="server" Width="50px" onkeypress="return onlyNumbers();">
</asp:TextBox>

it is not working in mozilla firefox(working perfectly in internet explorer).can any one please answer


Call the following function on form load

function isDecimalKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && charCode > 46 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    else {
        return true;
    }
}


txtNoSeat.Attributes["onKeyPress"] = "Javascript:return isNumberKey(event);";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜