/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@VladdyJun 25.2004 — The question that needs to be answered first is [b]why[/b] would you want to do that?
Copy linkTweet thisAlerts:
@k0r54authorJun 25.2004 — 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
Copy linkTweet thisAlerts:
@VladdyJun 25.2004 — Get ASCII chart, lookup code for "Backspace" and replace 13 with it.
Copy linkTweet thisAlerts:
@k0r54authorJun 25.2004 — i have number 8

[URL=http://www.atmospherecentral.com/learn/manual/javascript/KeyEventHandler.html]Here[/URL]

but it dont work ?

i tried that first of all
Copy linkTweet thisAlerts:
@VladdyJun 25.2004 — Then, I guess, the browser catches the event before it is passed to the page, which means you are out of luck.
Copy linkTweet thisAlerts:
@fredmvJun 25.2004 — Maybe try listening for it [font=courier]onkeydown[/font] instead of [font=courier]onkeypress[/font]. You might be able to catch the event that way.
Copy linkTweet thisAlerts:
@TNOSep 15.2004 — 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>
Copy linkTweet thisAlerts:
@LymedoOct 24.2006 — You don't know how long I have been looking for some code that would work on a data access page....THIS DOES! Thanks ? ? ?
Copy linkTweet thisAlerts:
@TNOOct 25.2006 — Wow, I forgot I was still submitted to get a reply to this 2 year old thread.
Copy linkTweet thisAlerts:
@shashank-joshiJun 07.2011 — Try following code to disable backspace- (It will work only for text fields and text areas)-

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" &amp;&amp; tag != "TEXTAREA")) {
return false;
}
if(src.type) {
var type = ("" + src.type).toUpperCase();
return type != "CHECKBOX" &amp;&amp; type != "RADIO" &amp;&amp; type != "BUTTON";
}
}
return true;
}
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...