Is there a library or a solution for achiving Tabs and Backtabs (Shift + Tab key), within HTML, using JavaScript?
I have found some solutions on the Internet, but none of them deals with Backtabs (Shift + Tab).
Help?
Is there a library or a solution for achiving Tabs and Backtabs (Shift + Tab key), within HTML, using JavaScript?
I have found some solutions on the Internet, but none of them deals with Backtabs (Shift + Tab).
Help?
I wrote a small JavaScript library that does exactly that: adds Tab and Shift+Tab functionality to HTML textarea elements. It's called Tab Override. You can try out the demo at http://wjbryant.github.io/taboverride/. There are no dependencies, but if you are using jQuery, there is also a jQuery wrapper plugin available for convenience.
Adding tabs to textareas is easy - you just add '\t'
. When thinking of shift-tabs, don't think of that as a character in it's own right, it's just the tab button whilst the shift is being pressed. You can achieve this by checking if the shift key is also pressed when the tab button is pressed, and if so, process the contents of your textarea depending on the content (presumably to the left of the cursor).
A nice example has been done in jQuery here, and a decent explanation on how to get the text around the text caret can be found here.
Here's a demo (that will need cleaning up before using in a real site!)
Note: I've not bothered with setting the caret position back to its original point - just concentrated on knocking up the demo from the above links.