Wednesday, September 5, 2012

Disable or Remove Comma in Asp Textbox

we can disable comma using jquery.

The code is given below

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#<%=txt.ClientID %>").keypress(function (e) {
                if (e.charCode == 44 || e.which == 44) {
                    if ($.browser.msie)
                        event.returnValue = false;

                    return false;
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txt" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>




$("#<%=txt.ClientID %>").keypress(function (e) {
                if (e.charCode == 44 || e.which == 44) {
                    if ($.browser.msie)
                        event.returnValue = false;

                    return false;
                }
            });



 e.charCode == 44 || e.which == 44  ----------  this is used because IE 7 does not support e.charCode.
 and all the other browsers support e.charCode.

-----------------------------------------------------------------------
if ($.browser.msie)
                        event.returnValue = false;

                    return false;


 -------------------------------------------------------------------------

$.browser.msie is used to check whether the currunet browser is IE or not.
IE 7 does not support return false. dats why we used event.returnValue =false. 

No comments:

Post a Comment