RadTextBox or RadNumbericTextBox Accept Only Number Using JavaScript in FireFox is Not Work

8 posts, 0 answers
  1. Misbakhul
    Misbakhul avatar
    7 posts
    Member since:
    May 2013

    Posted 21 Jul 2013 Link to this post

    Hi,
    dear all,

    i have ready use control telerik RadTextBox and RadNumericTextBox ,
    I want accept Only Number Using Javascript,
    I have Followed thread
    http://www.telerik.com/community/forums/aspnet-ajax/input/i-need-a-text-box-that-only-accepts-numbers.aspx
    and 
    http://www.telerik.com/community/forums/aspnet-ajax/general-discussions/radtextbox-need-to-be-restricted-only-for-integers.aspx

    I am following that trick,
    In IE is Fine and Work, But in FireFox is Not Work..

    some body can help....
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Jul 2013 Link to this post

    Hi

    Please have a look into the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" ClientEvents-OnKeyPress="OnKeyPress">
    </telerik:RadTextBox>

    JavaScript:
    <script type="text/javascript">
        function onkeypress(sender, args) {
            var keycode = args.get_keyCode()
            if (!(keycode >= 48 && keycode <= 57) || (keycode >= 96 && keycode <= 105)) {
                args.set_cancel(true);
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Misbakhul
    Misbakhul avatar
    7 posts
    Member since:
    May 2013

    Posted 22 Jul 2013 Link to this post

    trims shinu for your answer...

    I try your solution, but still does not work in firefox....
    I am using FireFox update 23.0...


    trims a lot..
  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 25 Jul 2013 Link to this post

    Hi Misbakhul,

    Thank you for contacting us.

    Since I was able to use two of the approaches from the threads you have mentioned that are working fine in IE, Chrome, Firefox 22.0 (last official version) and Firefox 23.0 beta, I will kindly ask you to provide a code snippet with how you are trying to implement this in your project. 

    I am attaching a simple project, demonstrating how you can achieve this behavior of the RadTextBox.

    Please try it and see if it works on your side.

    Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Misbakhul
    Misbakhul avatar
    7 posts
    Member since:
    May 2013

    Posted 27 Jul 2013 Link to this post

    hi Konstantin Dikov,
    trims to reply

    I implemented the code that I get from the samples that I got from the forum as well ..
    and any code samples you've ever applied in my project.
    problems is the same, before its possible sorry I forgot one thing,
    the piece of code you gave and I've never applied before its too successful, could mean only numbers.
    but it can not delete the number from RadTextBox or RadNumericTextBox when running applications in Firefox, even before his version could not ..can not Backspace...
    for this to be a problem in my client when the UAT process. because the application will be publicly hosting ..

    trims a lot.....
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Jul 2013 Link to this post

    Hi Misbakhul,

    I have added few lines to the Admin's code and You can try the following updated JavaScript in order to get the BackSpace key working in Firefox.

    JavaScript:
    function OnKeyPress(sender, args) {
        var keycode = args.get_keyCode()
        if (keycode == 8) {
            //Checking if the key pressed is BackSpace key, then do not cancel the event.
            return;
        }
        else if (!(keycode >= 48 && keycode <= 57) || (keycode >= 96 && keycode <= 105)) {
            args.set_cancel(true);
        }
    }

    JavaScript:
    function keyPress(sender, args) {
        if (args.get_keyCode() == 8) {
            return;
        }
        else {
            var text = sender.get_value() + args.get_keyCharacter();
            if (!text.match('^[0-9]+$'))
                args.set_cancel(true);
        }
    }

    Thanks,
    Shinu.
  8. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 30 Jul 2013 Link to this post

    Hi Misbakhul,

    In addition to Shinu's reply I want to add that RadNumericTextBox have that functionality out of the box and if there is no particular reason that you need to use RadTextBox, please consider using RadNumericTextBox instead.

    And just one more thing to add: If you experience some issues with RadNumericTextBox under Firefox 23 only, have in mind that this is still a beta version and not an official one (even though we have tested RadNumericTextBox under the latest Firefox Beta and no issues were present).
     

    Regards,
    Konstantin Dikov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  9. Kaos45
    Kaos45 avatar
    1 posts
    Member since:
    Jun 2012

    Posted 09 Apr 2015 Link to this post

    This worked like a charm, thanks much bro.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017