View Full Version : Disable TAB key

11-12-2006, 10:15 AM
Hello all i am trying to disable the tab button when the user loads up my page mainly to prevent them to tab to buttons once a overlay is displayed and waiting on them to enter something before continuing.

Here is the code im trying to get work but for some reason it doesnt like the TAB key...

<script language="JavaScript1.2">
function keyPressed() {
var TABkey = 15;
if (event.keyCode == TABkey) {
var strMessage = "Hello, there. I will help you";
strMessage += " in understanding various parts of this page.";

var strWindowProperties = "toolbar=no,location=no,status=no,";
strWindowProperties += "menubar=no,scrollbars=no,resizable=yes,";
strWindowProperties += "width=160,height=20";

var win = window.open (win, 'window', strWindowProperties);
win.document.write (strMessage);

<body onKeyDown="keyPressed()">

Any help would be great! :)

Philip M
11-12-2006, 01:03 PM
var TABkey = 09;

11-12-2006, 05:02 PM
Logical solution would be disabling button elements until they are ready to be used.

11-12-2006, 09:12 PM
Thanks Philip M, changing the number worked...

Vladdy: Care to share what you are talking about when u say disabling button elements?

The code i had above works now but i am still able to tab through everything once the box has been open.. I want a way to disable it totaly until they leave the site...


11-13-2006, 01:05 AM
Per HTML 4.01 disabled elements are skipped in tabbing navigation (http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#adef-disabled)
When you display your ovelay run a function that disables all form elements and enable them again when the overlay is closed.

11-13-2006, 04:06 AM
Yeah vlad it gives no code reference so i have no idea on how to do what its saying.. :confused:


11-13-2006, 06:09 AM
function enableAllButtons(onOff) //where onOff is true to enable buttons, false to disable
{ var allBtns = document.body.getElementByTagName('button');
for(var i=0; i<allBtns.length; i++) allBtns[i].disabled = !onOff;

11-13-2006, 06:44 AM
What would be the tag name if i wanted the links on the page not to be clickable? Or is that possible?

11-13-2006, 06:48 AM

You may look at his page, but you may not touch it!


11-13-2006, 06:53 AM
Yes correct :)

Im just trying to block anything for being clickabme if the overlay is on. Hints i can still click on stuff using the enter and tab key for this site even though its blocked with the mouse : http://www.pageflakes.com/


11-14-2006, 03:02 AM
function enablePage(onOff)
{ var formElements = ['button','input','select','textarea'];
for(var i=0; i<formElements.length; i++)
{ var elms = document.body.getElementByTagName(formElements[i]);
for(var j=0; i<elms.length; i++) elms[i].disabled = !onOff;
var links = document.body.getElementsByTagName('a');
for(var i=0; i<links.length; i++)
links.onclick = onOff?null:function(){return false;};