A lot of the time, when I want to format text within a web page's text box I'll hit the Tab key.

Unfortunately, that doesn't insert the tab character but instead moves the control to the next form element (like a button or a check box).

For browsers like Firefox/IE, is there a way to get the formatting behavior of a tab, within a text box, by typing a key combination?

link|improve this question

feedback

7 Answers

up vote 6 down vote accepted

Tabinta is a Firefox add-on that lets you do this.

link|improve this answer
Any solution for Chrome? – Sorin Sbarnea Mar 16 at 14:47
feedback

You can push ALT + 09

link|improve this answer
Be sure you are using the NumPad keys – CatamountJack Mar 17 '10 at 0:30
1  
This is perfect. To clarify (on any version of Windows): Hold your ALT key. Press and release 0 on the numeric keypad. Press and release 9 on the numeric keypad. Release the ALT key. Then cut and paste the Tab you just made if you have to do it a bunch! – Chris Mar 24 '10 at 0:38
@Chris: When I follow those exact instructions, it doesn't insert a tab character, but acts like the tab key. Did you try this in a web browser? – Casebash Apr 9 '10 at 4:39
@Casebash It works in this very comment window, in Chrome, in Windows 7 x64. – Chris Apr 25 '10 at 15:27
Only if you have Windows and a keyboard with a numpad. – Mechanical snail Oct 11 '11 at 4:15
show 2 more comments
feedback

If it's your site:

jQuery plugin: http://teddevito.com/demos/textarea.html

jQuery(document).ready(function () {

     $("textarea").tabby();

});

Load jQuery and the plugin first, then you can tab and make a tab, and shift+tab to "untab" as it were.

For browser-wide support, you will have to use an extension, userscript, plugin, etc. like: 46704 for Greasemonkey. (I would have linked, but I'm limited to 1.)

link|improve this answer
feedback

The big advantage of Tabinta in Firefox is that you can map the tab character to another hotkey, since you really don't want to lose the tab key default behavior in the browser.

With Internet Explorer you have no solution in the way of browser extensions that I am aware of. Here the only way is to keep the tab character in the clipboard by having previously copied it from some other program like notepad.

javascript solutions require the name of the textbox where they will act on, so this is far from ideal or practical. While alt keycode combinations under both browsers still execute the normal tab character keypress event so they don't work either.

link|improve this answer
feedback

To type the tab key in a text box, you can use a script like this (text box which accepts tab keys is named txtLongText):

[VB.NET]

txtLongText.Attributes.Add("onkeydown", _ "if(event.which || event.keyCode){if ((event.which == 9)" & _ "|| (event.keyCode == 9)) {document.getElementById('" & _ txtLongText.ClientID + "').selection = " & _ document.selection.createRange();" & _ txtLongText.ClientID & ".selection.text = " & _ " String.fromCharCode(9);return false;}} else {return true}; ")

[C#]

txtLongText.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 9)" + "|| (event.keyCode == 9)) {document.getElementById('"+ txtLongText.ClientID + "').selection = document.selection.createRange();" + txtLongText.ClientID + ".selection.text = String.fromCharCode(9);return false;}} else {return true}; ");

Or better, to avoid hard coding, you can put this code in a function named EnableTabType. The function has only one parameter, which specifies what is TextBox control where you need to enable typing of Tab characters.

[VB.NET]

Public Sub EnableTabType(tb As TextBox) tb.Attributes.Add("onkeydown", _ "if(event.which || event.keyCode){if((event.which == 9)" & _ "|| (event.keyCode == 9)) {document.getElementById('" & _ tb.ClientID & "').selection=document.selection.createRange();" & _ tb.ClientID & ".selection.text = " & _ " String.fromCharCode(9);return false;}}else{return true};") End Sub

[C#]

public void EnableTabType(TextBox tb) { tb.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 9)" + "|| (event.keyCode == 9)) {document.getElementById('"+ tb.ClientID + "').selection = document.selection.createRange();" + tb.ClientID + ".selection.text = String.fromCharCode(9);return false;}} else {return true}; ");

Source

link|improve this answer
feedback

Could someone make it easier? In vb.net just set an attribute of textbox object. See property named "AcceptsTab". Just set it to "true" and you will get your textbox accept your tab character...

link|improve this answer
feedback

I've messed wit AutoHotkey a bit to get this ability, and the only 'bulletproof' solution I found is really to paste (not send) the tab character itself.

;
; TAB character
; pasted from clipboard
; win tab
;
#tab::
old_clip:=clipboard
clipboard:=A_Tab
clipWait
sendInput,^v
clipboard:=old_clip
clipWait
return

It turns out that this AHK bind is even useful in text editors that handles the TAB keystroke extra; eg. IDE configured to use autoindent-by-spaces.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.