disable back space button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

disable back space button

Post by myasirm »

hi guys i want to disable the back space button bcoz i click it for removing the words from text box it is going back to previous page so kindly help in this regards if any one know
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: disable back space button

Post by desperado »

wrong forum. you need to use javascript to detect a specific keypress and assign it an action. .
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

Re: disable back space button

Post by myasirm »

so any one know java script for that issue kindly help me in this regards
waiting for ur replies
thanks
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: disable back space button

Post by Eric! »

All you need to do is to use google... :|
This will disable it in text areas. Put this in the < head> section.

Code: Select all

<script type="text/javascript"> 
 
function stopBKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 8) && (node.type=="text"))  {return false;} 
} 
 
document.onkeypress = stopBKey; 
 
</script>
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: disable back space button

Post by Mirge »

That would get extremely annoying. Fast.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: disable back space button

Post by Mirge »

McInfo wrote:The only reason I can think of that the backspace key would cause the browser to go back a page instead of removing characters from a text input is if the text input does not have focus.
Exactly what I was thinking.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: disable back space button

Post by Eric! »

SHHHH!!! I get a good laugh when I think of all those people trying to fix their typos and wondering what the hell happend to their keyboard.

(Ok, I also didn't know not having set the focus could do that...)
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

Re: disable back space button

Post by myasirm »

my issue was that when i enter back space button from my keyboard it goes to previous but that is happening when there is no thing selected in the form so i want to stop that back howz that possible???
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

Re: disable back space button

Post by myasirm »

guys i used this code for that issue it is working properly but back space button is not working on text area can any one tell me why that is happening how can i solva that issue now???

<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>
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: disable back space button

Post by Mirge »

Which browser, version, and OS are you using?
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

Re: disable back space button

Post by myasirm »

dear same code i have used and same problem is on my side i am using windows server2003 and browser is internet explorer so kindly tell me which changes i have to do to resolve that issue??
Post Reply