Skip to main content
February 5, 2007
Question

Disable Backspace when in input text fields

  • February 5, 2007
  • 2 replies
  • 1631 views
Im trying to find a way to disable the keyboard backspace button from going back a page in the site but allowing it to function as a character delete when needed for typing in an input text field of a form.
Strangely this problem only occurs for about a minute after the page is opened....after that it then works correctly. You can see what I mean by accessing the site's contact page
www.safetybusiness.co.uk

I have found two different sets of code to disable the Backspace completely, but this then means it doesn't work at all when wanting to delete in the text field.

Method 1:

<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>


Method 2:

<script>
function checkShortcut()
{
if(event.keyCode==8 || event.keyCode==13)
{
return false;
}
}
</script>
<body onkeydown="return checkShortcut()">

Anyone know how I can overcome this?
This topic has been closed for replies.

2 replies

Inspiring
February 28, 2007
The TextField class has a tab order property. You may want to look into this. As for disabling the backspace key, you can grab key presses from user input. I'm not 100% on this but you could use Flash to test the key being pressed. If backspace is pressed, find out the current object with focus (unsure of this part), if it's an input box in flash, have flash handle it or if a text box doesn't have focus, send it out to javascript to have it handle it.
February 27, 2007
UPDATE:

Still haven't found a solution to this. But I have noticed that if i press the tab key and highlight the respective input box I can then use the backspace key to delete. How do I tell the website to focus on the input boxes and not navigation without using the tab key??
this is a most frustrating problem. please help.