开发者

numeric validation not working in firefox

开发者 https://www.devze.com 2023-03-26 13:05 出处:网络
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

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

精彩评论

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