dcsimg
www.webdeveloper.com
Results 1 to 11 of 11

Thread: Disable Backspace

  1. #1
    Join Date
    Jun 2004
    Posts
    1,299

    Disable Backspace

    Hi,

    Just a quicky how can i disable the backspace. I have found code for the enter key but dont understand it. So any help will be great thanks

    <script language="JavaScript" type="text/javascript">

    function checkCR(evt) {

    var evt = (evt) ? evt : ((event) ? event : null);

    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}

    }

    document.onkeypress = checkCR;

    </script>

    Tnx Adz

  2. #2
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    The question that needs to be answered first is why would you want to do that?
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.

  3. #3
    Join Date
    Jun 2004
    Posts
    1,299
    The reason why is because, at work our agents use webscript and on the web script there is an ocx, but when you press back space it goes back a page and i cant do anything about it.

    So the best way is to disable backspace on that page.

    Thanks Adam

  4. #4
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    Get ASCII chart, lookup code for "Backspace" and replace 13 with it.
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.

  5. #5
    Join Date
    Jun 2004
    Posts
    1,299
    i have number 8

    Here

    but it dont work

    i tried that first of all

  6. #6
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    Then, I guess, the browser catches the event before it is passed to the page, which means you are out of luck.
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.

  7. #7
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,487
    Maybe try listening for it onkeydown instead of onkeypress. You might be able to catch the event that way.

  8. #8
    Join Date
    Sep 2004
    Posts
    294
    Try This:

    <script type="text/javascript">

    if (typeof window.event != 'undefined')
    document.onkeydown = function()
    {
    if (event.srcElement.tagName.toUpperCase() != 'INPUT')
    return (event.keyCode != 8);
    }
    else
    document.onkeypress = function(e)
    {
    if (e.target.nodeName.toUpperCase() != 'INPUT')
    return (e.keyCode != 8);
    }

    </script>

  9. #9
    Join Date
    Oct 2006
    Posts
    1

    Smile Thanks

    You don't know how long I have been looking for some code that would work on a data access page....THIS DOES! Thanks

  10. #10
    Join Date
    Sep 2004
    Posts
    294
    Wow, I forgot I was still submitted to get a reply to this 2 year old thread.

  11. #11
    Join Date
    Jun 2011
    Posts
    1

    Smile disable backspace-

    Try following code to disable backspace- (It will work only for text fields and text areas)-

    Code:
    document.onkeydown = function () {
    	var e = event || window.event;
    	var keyASCII = parseInt(e.keyCode, 10);
    	var src = e.srcElement;
    	var tag = src.tagName.toUpperCase();
    	if(keyASCII == 13) {
    		return false;
    	}
    	if(keyASCII == 8) {
    		if(src.readOnly || src.disabled || (tag != "INPUT" && tag != "TEXTAREA")) {
    			return false;
    		}
    		if(src.type) {
    			var type = ("" + src.type).toUpperCase();
    			return type != "CHECKBOX" && type != "RADIO" && type != "BUTTON";
    		}
    	}
    	return true;
    }

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