Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alert when backspace is pressed inside textbox

    Hi,

    I have a grid wih three read-only columns. Whenever user goes in there and try to edit by pressing backspace, I need to alert by giving a message. I am using this script and it doesn't work? Can anyone correct me?


    $(document).ready(function () {
    $('#txtCode').on('keyup keydown', function (e) {
    if (e.which == 8) {
    alert('The column is read-only and is not editable');
    }
    });
    });

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,915
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    There is nothing obviously wrong with that code. But that code also does nothing by itself, it is associated with some kind of HTML, and as long as you don’t show that nobody can help you.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,683
    Thanks
    25
    Thanked 656 Times in 655 Posts
    Will definitely work for a textarea. Tested because of 'keyup keydown' which works, but "keydown" by itself would surfice and "readonly" is an attribute for the textarea that may work for you without JQ.
    Last edited by sunfighter; 12-27-2013 at 04:27 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •