Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: Disable TAB key

  1. #1
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Exclamation Disable TAB key

    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...
    Code:
    <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);
       }
    }
    </script>
    </head>
    
    
    <body onKeyDown="keyPressed()">

    Any help would be great!
    David
    Last edited by StealthRT; 11-12-2006 at 09:33 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,927
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    var TABkey = 09;

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Logical solution would be disabling button elements until they are ready to be used.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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...

    David

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Per HTML 4.01 disabled elements are skipped in tabbing navigation
    When you display your ovelay run a function that disables all form elements and enable them again when the overlay is closed.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #6
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Yeah vlad it gives no code reference so i have no idea on how to do what its saying..

    David

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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;
      }
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #8
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    What would be the tag name if i wanted the links on the page not to be clickable? Or is that possible?

  • #9
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Location
    Vostok Station, AQ
    Posts
    602
    Thanks
    35
    Thanked 3 Times in 3 Posts
    LOL!


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

    <div> - putting your mind in a box since 1997

  • #10
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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/

    David

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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;};
      }
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •