You must Sign In to post a response.
  • Category: JQuery

    Allow only numbers in textbox inside JQgrid

    I have JQGrid in my application.In side JQgrid i have "MaxLimit" text box..here i wana accept only numbers to enter in this textbox...how can i achieve????simple code plz....is that possible in JQgrid???
  • #754986
    get that id of the textbox and
    place it in the code
    $("txt").keypress(function (e)
    {
    if(e.which!=8 && e.which!=0 && (e.which <48 || e.which >57))
    {
    display error msg here
    }
    }

  • #755028
    Hi,

    Refer below sample for your reference.


    <script type="text/javascript">
    function IsNumFieldKeyPress() {
    var element;
    element = event.srcElement;
    if (event.keyCode >= 48 && event.keyCode <= 57) {//to handle num 0 -9
    event.returnValue = true;
    return;
    }
    </script>

    <asp:TextBox ID="txtMaterialQty" runat="server" width="90%" onkeypress="IsNumFieldKeyPress();" Enabled="false" Tooltip="Enter Additonal Quantity (+) or (-), Not Total Quantity" />



    Try something like above to achieve your goal.

    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #755048
    Thx friends

  • #757563
    Hi,

    there are so many ways to do this by regx script etc
    one of thes is controlling charkeys by javascript code snippet bellow shows the same please have a look on it

    <!DOCTYPE html>
    <HTML>
    <HEAD>
    <SCRIPT language=Javascript>
    function isNumberKey(evt)
    {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">
    </BODY>
    </HTML>



    Regards
    SriSunny


  • Sign In to post your comments