www.webdeveloper.com
Results 1 to 4 of 4

Thread: Disable Backspace (event.keyCode==8)???

  1. #1
    Join Date
    Aug 2006
    Posts
    119

    Disable Backspace (event.keyCode==8)???

    I am trying to disable a backspace via javascript, but it seems that event.keyCode==8, as google told me, is not a backspace code. As well trying to alert keyCode the backspace did not return any values.... 0.o

    my code up to now is:
    Code:
    function checkKey() {  //Function to disable "backspace Key"
    	alert (event.keyCode);
    	var key = event.keyCode; 
    	if (key == 8) { event.keyCode=9; return (event.keyCode);} 
    } 
    .
    .
    <body onKeyPress="checkKey()">
    Any suggestions or alternative ideas how can I prvent the user going back??

  2. #2
    Join Date
    Nov 2002
    Posts
    94
    backspace is keycode 8.

    Code:
    <script>
    function keyCheck(){
    alert("KeyCode = "+event.keyCode);}
    document.onkeydown=keyCheck;
    </script>
    -=[ kdcgrohl.com ]=- JavaScripts, Site Protection, Etc...

  3. #3
    Join Date
    Feb 2006
    Posts
    2,927
    keypress returns a value for a character in keyCode in IE and charCode in firefox.
    all keys can be read as keycode from the keydown event type.


    catch the event and examine the keyCode on keydown.

    If you are handling key events only on the body element you will not
    be catching events in textareas and inputs until after they have
    been processed and returned normally and bubble up to the body-
    technically speaking, this is locking the barn door after the horse is stolen.

    Attach your event handler to the elements that accept key events.
    Last edited by mrhoo; 12-28-2006 at 03:22 PM.

  4. #4
    Join Date
    Aug 2006
    Posts
    119
    Intrestiong onkeypress there is no keycode for backspace, but onkeydown there is... hmm..

    Anyways should think of anything else, coz this does not work with FF.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles