Home
About
Contact
Categories
Classic ASP (5 - Sub-Categories)
JavaScript (2 - Sub-Categories)
Databases (1 - Sub-Category)
ASP.NET (3 - Sub-Categories)
Delphi (1 - Sub-Category)
Windows Server Core (1 - Sub-Category)
VMWare (1 - Sub-Category)
New CFFCS Coding Source is still in Beta
Please report any errors to the [Contact] page. Thank you.
Classic ASP (5)
JavaScript (2)
Databases (1)
ASP.NET (3)
Delphi (1)
Windows Server Core (1)
VMWare (1)
Resources
[View The Source Code For This Project]
JavaScript
How-To
Use the tab key in a textarea
HTML
Type in some words with a tab between them to get what we have below. You can also edit the CSS. Click on the [CSS Tab] and edit the textarea style. <textarea id="Mytextarea"> Hello test this out here </textarea>
CSS
#Mytextarea{ width:23.5em; height:10em; }
JavaScript
JS
document.getElementById('Mytextarea').addEventListener('keydown', function(e) { if (e.key == 'Tab') { e.preventDefault(); var start = this.selectionStart; var end = this.selectionEnd; // set textarea value to: text before caret + tab + text after caret this.value = this.value.substring(0, start) + "\t" + this.value.substring(end); // put caret at right position again this.selectionStart = this.selectionEnd = start + 1; } });
Preview
Tags
Use the tab key in a textarea
Event Listener
keydown function
HTML document