Please help me with the TAB character!

Posted on 2004-11-25
Last Modified: 2013-12-03
Hi there!
When you open notepad, and press the TAB button on the keyboard, it moves the cursor to some new place from its previous position (say 8 characters far from it). You can have the same effect when you press and hold Alt key, then type 09 and release all keys.
The same way, you can go to a new line, when you press the enter key, or when you type ALT+013 or ALT+010 (I know the difference of the last two.)
Now, go to the textarea right below here, where you can type an answer to my question!
The "Enter" button and ALT+013 are working correctly. ALT+010 is not working. I can suppose that I understand why it happens, though I can not understand it completely. But the main question is not that:
In the same textarea, if you press TAB key, you will be moved to the submit button; if you press ALT+09 it does not move the cursor; but if you copy and paste that empty space created by pressing TAB key in notepad area, you can have the same space inside the text area!
I want a way to create a same effect when typing inside a text area, without having to copy and paste this TAB-made space from another source.
Question by:Shablon
    LVL 6

    Expert Comment

    Something like this?

                function trapTab(textarea) {
                    if (window.event.keyCode == 9) {
                        textarea.value += '\t';
                        return false;
                <textarea onkeydown="return trapTab(this);"></textarea>

    Author Comment

    Oops!! You have given me an excellent answer, but this is not my question!!
    I am not going to create a page in which people can use TAB key with it's space creating action! I am not going to create a page at all! I am just looking for a way to be used by me myself as a USER (not a designer) to type a TAB character inside any text area!
    Example: I want to post some code here. I want to type it inside the "Post a OCmment" textarea right now. I want to use TAB character too. What keys should I press then?
    LVL 53

    Accepted Solution

    Not gonna happen.  The tab key by default is used to traverse the inputs.  Unless the developers put scripting on a page to alter that behaviour that is what the browser is going to do.  The cut an paste of the tab character is the only way you are going to get it in there.  Perhaps you can setup one of your function keys to generate it from the clipboard.  I'm not sure if it will be stripped on the server or not.  So even if you put it in it may not show up when the comment is displayed on the page anyway.


    Author Comment

    Excuse me for asking this again, but, I can accept that the TAB key is designed to move us to the next item in IE and other browsers, but why ALT+09 does exactly NOTHING? It neither creates that space nor moves to the next object in the page!
    LVL 53

    Expert Comment

    Because whomever wrote the specifications decided to do it that way. I see no practical value in researching why they did it or who did it.  At best it is an answer to a trivia question, and my time can be put to more productive pursuits.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now