Question
Disable Backspace when in input text fields
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?
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?